forked from ezsystems/repository-forms
/
ViewBuilderRegistryPass.php
43 lines (37 loc) · 1.59 KB
/
ViewBuilderRegistryPass.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
/**
* This file is part of the eZ RepositoryForms package.
*
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
namespace EzSystems\RepositoryFormsBundle\DependencyInjection\Compiler;
use EzSystems\RepositoryForms\Content\View\Builder\ContentCreateViewBuilder;
use EzSystems\RepositoryForms\Content\View\Builder\ContentEditViewBuilder;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
/**
* Compiler pass to add View Builders to ViewBuilderRegistry.
*/
class ViewBuilderRegistryPass implements CompilerPassInterface
{
const VIEW_BUILDER_REGISTRY = 'ezpublish.view_builder.registry';
const VIEW_BUILDER_CONTENT_EDIT = ContentEditViewBuilder::class;
const VIEW_BUILDER_CONTENT_CREATE = ContentCreateViewBuilder::class;
public function process(ContainerBuilder $container)
{
if (
!$container->hasDefinition(self::VIEW_BUILDER_REGISTRY)
|| !$container->hasDefinition(self::VIEW_BUILDER_CONTENT_EDIT)
|| !$container->hasDefinition(self::VIEW_BUILDER_CONTENT_CREATE)
) {
return;
}
$registry = $container->findDefinition(self::VIEW_BUILDER_REGISTRY);
$viewBuilders = [
$container->getDefinition(self::VIEW_BUILDER_CONTENT_EDIT),
$container->getDefinition(self::VIEW_BUILDER_CONTENT_CREATE),
];
$registry->addMethodCall('addToRegistry', [$viewBuilders]);
}
}