Completed
Pull Request — master (#5032)
by Grégoire
03:41
created

FakeTemplateRegistryExtension::getAdminTemplate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 9
nc 2
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Sonata Project package.
7
 *
8
 * (c) Thomas Rabaix <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Sonata\AdminBundle\Tests\Twig\Extension;
15
16
use Twig\Extension\AbstractExtension;
17
use Twig\TwigFunction;
18
19
class FakeTemplateRegistryExtension extends AbstractExtension
20
{
21
    public function getFunctions()
22
    {
23
        return [
24
            new TwigFunction('get_admin_template', [$this, 'getAdminTemplate']),
25
        ];
26
    }
27
28
    public function getAdminTemplate($name, $adminCode)
29
    {
30
        $templates = [
31
            'base_list_field' => '@SonataAdmin/CRUD/base_list_field.html.twig',
32
        ];
33
34
        if (isset($templates[$name])) {
35
            return $templates[$name];
36
        }
37
38
        throw new \Exception(sprintf(
39
            'Template "%s" of Admin "%s" not found in FakeTemplateRegistry',
40
            $name,
41
            $adminCode
42
        ));
43
    }
44
}
45