Completed
Pull Request — 5.0 (#2103)
by Kevin
10:13
created

AdminListBundle/Twig/AdminListTwigExtension.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Kunstmaan\AdminListBundle\Twig;
4
5
use Kunstmaan\AdminListBundle\AdminList\AdminList;
6
use Kunstmaan\AdminListBundle\Service\ExportService;
7
use Twig_Environment;
8
use Twig_Extension;
9
use Twig_SimpleFunction;
10
11
/**
12
 * AdminListTwigExtension
13
 */
14
class AdminListTwigExtension extends Twig_Extension
15
{
16
    /**
17
     * Returns a list of functions to add to the existing list.
18
     *
19
     * @return array An array of functions
20
     */
21 View Code Duplication
    public function getFunctions()
22
    {
23
        return [
24
            new Twig_SimpleFunction('adminlist_widget', [$this, 'renderWidget'], ['needs_environment' => true, 'is_safe' => ['html']]),
25
            new Twig_SimpleFunction('adminthumb_widget', [$this, 'renderThumbWidget'], ['needs_environment' => true, 'is_safe' => ['html']]),
26
            new Twig_SimpleFunction('supported_export_extensions', [$this, 'getSupportedExtensions']),
27
        ];
28
    }
29
30
    /**
31
     * Renders the HTML for a given view
32
     *
33
     * Example usage in Twig:
34
     *
35
     *     {{ form_widget(view) }}
36
     *
37
     * You can pass options during the call:
38
     *
39
     *     {{ form_widget(view, {'attr': {'class': 'foo'}}) }}
40
     *
41
     *     {{ form_widget(view, {'separator': '+++++'}) }}
42
     *
43
     * @param Twig_Environment $env
44
     * @param AdminList        $view      The view to render
45
     * @param string           $basepath  The base path
46
     * @param array            $urlparams Additional url params
47
     * @param array            $addparams Add params
48
     *
49
     * @return string The html markup
50
     *
51
     * @throws \Throwable
52
     * @throws \Twig_Error_Loader
53
     * @throws \Twig_Error_Runtime
54
     * @throws \Twig_Error_Syntax
55
     */
56 View Code Duplication
    public function renderWidget(Twig_Environment $env, AdminList $view, $basepath, array $urlparams = [], array $addparams = [])
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
57
    {
58
        $filterBuilder = $view->getFilterBuilder();
59
60
        return $env->render(
61
            'KunstmaanAdminListBundle:AdminListTwigExtension:widget.html.twig',
62
            [
63
                'filter' => $filterBuilder,
64
                'basepath' => $basepath,
65
                'addparams' => $addparams,
66
                'extraparams' => $urlparams,
67
                'adminlist' => $view,
68
            ]
69
        );
70
    }
71
72
    /**
73
     * Renders the HTML for a given view
74
     *
75
     * Example usage in Twig:
76
     *
77
     *     {{ form_widget(view) }}
78
     *
79
     * You can pass options during the call:
80
     *
81
     *     {{ form_widget(view, {'attr': {'class': 'foo'}}) }}
82
     *
83
     *     {{ form_widget(view, {'separator': '+++++'}) }}
84
     *
85
     * @param Twig_Environment $env
86
     * @param AdminList        $view      The view to render
87
     * @param string           $basepath  The base path
88
     * @param array            $urlparams Additional url params
89
     * @param array            $addparams Add params
90
     *
91
     * @return string The html markup
92
     *
93
     * @throws \Throwable
94
     * @throws \Twig_Error_Loader
95
     * @throws \Twig_Error_Runtime
96
     * @throws \Twig_Error_Syntax
97
     */
98 View Code Duplication
    public function renderThumbWidget(Twig_Environment $env, AdminList $view, $basepath, array $urlparams = [], array $addparams = [])
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
99
    {
100
        $filterBuilder = $view->getFilterBuilder();
101
102
        return $env->render(
103
            'KunstmaanAdminListBundle:AdminListTwigExtension:thumbwidget.html.twig',
104
            [
105
                'filter' => $filterBuilder,
106
                'basepath' => $basepath,
107
                'addparams' => $addparams,
108
                'extraparams' => $urlparams,
109
                'adminlist' => $view,
110
            ]
111
        );
112
    }
113
114
    /**
115
     * @return array
116
     */
117
    public function getSupportedExtensions()
118
    {
119
        return ExportService::getSupportedExtensions();
120
    }
121
}
122