sonata-project / SonataAdminBundle

@@ -55,7 +55,9 @@
Loading
55 55
            ->tag('twig.extension')
56 56
            ->args([
57 57
                new ReferenceConfigurator('sonata.admin.global_template_registry'),
58 +
                // NEXT_MAJOR: Remove next line.
58 59
                new ReferenceConfigurator('service_container'),
60 +
                new ReferenceConfigurator('sonata.admin.pool'),
59 61
            ])
60 62
61 63
        ->set('sonata.admin.group.extension', GroupExtension::class)

@@ -14,6 +14,8 @@
Loading
14 14
namespace Sonata\AdminBundle\Twig\Extension;
15 15
16 16
use Sonata\AdminBundle\Admin\AdminInterface;
17 +
use Sonata\AdminBundle\Admin\Pool;
18 +
use Sonata\AdminBundle\Exception\AdminCodeNotFoundException;
17 19
use Sonata\AdminBundle\Templating\TemplateRegistryInterface;
18 20
use Symfony\Component\DependencyInjection\ContainerInterface;
19 21
use Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException;
@@ -29,14 +31,29 @@
Loading
29 31
    private $globalTemplateRegistry;
30 32
31 33
    /**
34 +
     * NEXT_MAJOR: Remove this property.
35 +
     *
32 36
     * @var ContainerInterface
33 37
     */
34 38
    private $container;
35 39
36 -
    public function __construct(TemplateRegistryInterface $globalTemplateRegistry, ContainerInterface $container)
40 +
    /**
41 +
     * NEXT_MAJOR: Remove "null" from var type.
42 +
     *
43 +
     * @var Pool|null
44 +
     */
45 +
    private $pool;
46 +
47 +
    /**
48 +
     * @internal since sonata-project/admin-bundle 4. This class should only be used through Twig
49 +
     *
50 +
     * NEXT_MAJOR: Remove $container parameter and make Pool mandatory.
51 +
     */
52 +
    public function __construct(TemplateRegistryInterface $globalTemplateRegistry, ContainerInterface $container, ?Pool $pool = null)
37 53
    {
38 54
        $this->globalTemplateRegistry = $globalTemplateRegistry;
39 55
        $this->container = $container;
56 +
        $this->pool = $pool;
40 57
    }
41 58
42 59
    /**
@@ -86,18 +103,13 @@
Loading
86 103
    }
87 104
88 105
    /**
89 -
     * @throws ServiceNotFoundException
90 -
     * @throws ServiceCircularReferenceException
106 +
     * @throws AdminCodeNotFoundException
91 107
     */
92 108
    private function getTemplateRegistry(string $adminCode): TemplateRegistryInterface
93 109
    {
94 -
        $serviceId = sprintf('%s.template_registry', $adminCode);
95 -
        $templateRegistry = $this->container->get($serviceId);
96 -
        if ($templateRegistry instanceof TemplateRegistryInterface) {
97 -
            return $templateRegistry;
98 -
        }
110 +
        $admin = $this->pool->getAdminByAdminCode($adminCode);
99 111
100 -
        throw new ServiceNotFoundException($serviceId);
112 +
        return $admin->getTemplateRegistry();
101 113
    }
102 114
103 115
    /**
Files Complexity Coverage
src 2,851 80.51%
Project Totals (191 files) 2851 80.51%
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading