|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* File containing the FieldRegistryPass class. |
|
5
|
|
|
* |
|
6
|
|
|
* @copyright Copyright (C) eZ Systems AS. All rights reserved. |
|
7
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
|
8
|
|
|
*/ |
|
9
|
|
|
namespace eZ\Publish\Core\Base\Container\Compiler\Search; |
|
10
|
|
|
|
|
11
|
|
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
|
12
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
13
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
|
14
|
|
|
use LogicException; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* This compiler pass will register eZ Publish indexable field types. |
|
18
|
|
|
*/ |
|
19
|
|
|
class FieldRegistryPass implements CompilerPassInterface |
|
20
|
|
|
{ |
|
21
|
|
|
public const EZPUBLISH_FIELD_TYPE_INDEXABLE = 'ezpublish.fieldType.indexable'; |
|
22
|
|
|
public const EZPLATFORM_FIELD_TYPE_INDEXABLE = 'ezplatform.field_type.indexable'; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container |
|
26
|
|
|
* |
|
27
|
|
|
* @throws \LogicException |
|
28
|
|
|
*/ |
|
29
|
|
|
public function process(ContainerBuilder $container) |
|
30
|
|
|
{ |
|
31
|
|
|
if (!$container->hasDefinition('ezpublish.search.common.field_registry')) { |
|
32
|
|
|
return; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
$fieldRegistryDefinition = $container->getDefinition('ezpublish.search.common.field_registry'); |
|
36
|
|
|
|
|
37
|
|
|
$ezpublishIndexableFieldTypeTags = $container->findTaggedServiceIds(self::EZPUBLISH_FIELD_TYPE_INDEXABLE); |
|
38
|
|
|
foreach ($ezpublishIndexableFieldTypeTags as $ezpublishIndexableFieldTypeTag) { |
|
39
|
|
|
@trigger_error( |
|
|
|
|
|
|
40
|
|
|
sprintf( |
|
41
|
|
|
'`%s` service tag is deprecated and will be removed in eZ Platform 4.0. Please use `%s`. instead.', |
|
42
|
|
|
self::EZPUBLISH_FIELD_TYPE_INDEXABLE, |
|
43
|
|
|
self::EZPLATFORM_FIELD_TYPE_INDEXABLE |
|
44
|
|
|
), |
|
45
|
|
|
E_USER_DEPRECATED |
|
46
|
|
|
); |
|
47
|
|
|
} |
|
48
|
|
|
$ezplatformIndexableFieldTypeTags = $container->findTaggedServiceIds(self::EZPLATFORM_FIELD_TYPE_INDEXABLE); |
|
49
|
|
|
$fieldTypesTags = array_merge($ezpublishIndexableFieldTypeTags, $ezplatformIndexableFieldTypeTags); |
|
50
|
|
|
foreach ($fieldTypesTags as $id => $attributes) { |
|
51
|
|
|
foreach ($attributes as $attribute) { |
|
52
|
|
|
if (!isset($attribute['alias'])) { |
|
53
|
|
|
throw new LogicException( |
|
54
|
|
|
'ezpublish.fieldType.indexable or ezplatform.field_type.indexable service tag needs an "alias" attribute to ' . |
|
55
|
|
|
'identify the indexable field type. None given.' |
|
56
|
|
|
); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
$fieldRegistryDefinition->addMethodCall( |
|
60
|
|
|
'registerType', |
|
61
|
|
|
array( |
|
62
|
|
|
$attribute['alias'], |
|
63
|
|
|
new Reference($id), |
|
64
|
|
|
) |
|
65
|
|
|
); |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|
If you suppress an error, we recommend checking for the error condition explicitly: