1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @copyright Copyright (C) eZ Systems AS. All rights reserved. |
5
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
6
|
|
|
*/ |
7
|
|
|
namespace eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Compiler; |
8
|
|
|
|
9
|
|
|
use eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\SlugConverter; |
10
|
|
|
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; |
11
|
|
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
12
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* This compiler pass will create configuration injected into SlugConverter responsible for url pattern creation. |
16
|
|
|
*/ |
17
|
|
|
class SlugConverterConfigurationPass implements CompilerPassInterface |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* {@inheritdoc} |
21
|
|
|
*/ |
22
|
|
|
public function process(ContainerBuilder $container) |
23
|
|
|
{ |
24
|
|
|
if (!$container->has('ezpublish.persistence.slug_converter')) { |
25
|
|
|
return; |
26
|
|
|
} |
27
|
|
|
$slugConverterDefinition = $container->getDefinition('ezpublish.persistence.slug_converter'); |
28
|
|
|
|
29
|
|
|
$parameterConfiguration = $slugConverterDefinition->getArgument(1); |
30
|
|
|
$semanticConfiguration = $container->getParameter('ezpublish.url_alias.slug_converter'); |
31
|
|
|
|
32
|
|
|
$mergedConfiguration = $parameterConfiguration; |
33
|
|
|
|
34
|
|
|
if (isset($semanticConfiguration['transformation'])) { |
35
|
|
|
$mergedConfiguration['transformation'] = $semanticConfiguration['transformation']; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
if (isset($semanticConfiguration['separator'])) { |
39
|
|
|
$mergedConfiguration['wordSeparatorName'] = $semanticConfiguration['separator']; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
$transformationGroups = $parameterConfiguration['transformationGroups'] ?? SlugConverter::DEFAULT_CONFIGURATION['transformationGroups']; |
43
|
|
|
|
44
|
|
|
if (isset($semanticConfiguration['transformation_groups'])) { |
45
|
|
|
$mergedConfiguration['transformationGroups'] = array_merge_recursive( |
46
|
|
|
$transformationGroups, |
47
|
|
|
$semanticConfiguration['transformation_groups'] |
48
|
|
|
); |
49
|
|
|
|
50
|
|
|
foreach ($semanticConfiguration['transformation_groups'] as $group => $groupConfig) { |
51
|
|
|
if (isset($groupConfig['cleanup_method'])) { |
52
|
|
|
$mergedConfiguration['transformationGroups'][$group]['cleanupMethod'] = $groupConfig['cleanup_method']; |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
if (isset($mergedConfiguration['transformation']) && |
58
|
|
|
!array_key_exists($mergedConfiguration['transformation'], $mergedConfiguration['transformationGroups'])) { |
59
|
|
|
throw new InvalidConfigurationException(sprintf( |
60
|
|
|
"Unknown transformation group selected: '%s'.\nAvailable ones: '%s'", |
61
|
|
|
$mergedConfiguration['transformation'], |
62
|
|
|
implode(', ', array_keys($mergedConfiguration['transformationGroups'])) |
63
|
|
|
)); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
$slugConverterDefinition->setArgument(1, $mergedConfiguration); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|