Completed
Push — 3.x ( 799626...732596 )
by Grégoire
04:11
created

FakeTemplateRegistryExtension::getFunctions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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