Completed
Pull Request — 5.6 (#2830)
by Jeroen
14:14
created

Twig/Extension/PagePartAdminTwigExtension.php (1 issue)

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\PagePartBundle\Twig\Extension;
4
5
use Kunstmaan\PagePartBundle\PagePartAdmin\PagePartAdmin;
6
use Twig\Environment;
7
use Twig\Extension\AbstractExtension;
8
use Twig\TwigFunction;
9
10
/**
11
 * PagePartAdminTwigExtension
12
 *
13
 * @final since 5.4
14
 */
15
class PagePartAdminTwigExtension extends AbstractExtension
16
{
17
    private $usesExtendedPagePartChooser = false;
18
19
    /**
20
     * @return array
21
     */
22
    public function getFunctions()
23
    {
24
        return [
25
            new TwigFunction('pagepartadmin_widget', [$this, 'renderWidget'], ['needs_environment' => true, 'is_safe' => ['html']]),
26
        ];
27
    }
28
29
    /**
30
     * Renders the HTML for a given pagepart
31
     *
32
     * Example usage in Twig:
33
     *
34
     *     {{ pagepartadmin_widget(ppAdmin) }}
35
     *
36
     * You can pass options during the call:
37
     *
38
     *     {{ pagepartadmin_widget(ppAdmin, {'attr': {'class': 'foo'}}) }}
39
     *
40
     *     {{ pagepartadmin_widget(ppAdmin, {'separator': '+++++'}) }}
41
     *
42
     * @param PagePartAdmin $ppAdmin      The pagepart admin to render
43
     * @param Form          $form         The form
44
     * @param array         $parameters   Additional variables passed to the template
45
     * @param string        $templateName
46
     *
47
     * @return string The html markup
48
     */
49
    public function renderWidget(Environment $env, PagePartAdmin $ppAdmin, $form = null, array $parameters = [], $templateName = null)
50
    {
51
        if ($templateName === null) {
52
            $templateName = '@KunstmaanPagePart/PagePartAdminTwigExtension/widget.html.twig';
53
        }
54
55
        $template = $env->load($templateName);
56
57
        return $template->render(array_merge($parameters, [
58
            'pagepartadmin' => $ppAdmin,
59
            'page' => $ppAdmin->getPage(),
60
            'form' => $form,
61
            'extended' => $this->usesExtendedPagePartChooser,
62
        ]));
63
    }
64
65
    /**
66
     * Get usesExtendedPagePartChooser.
67
     *
68
     * @return usesExtendedPagePartChooser
69
     */
70
    public function getUsesExtendedPagePartChooser()
71
    {
72
        return $this->usesExtendedPagePartChooser;
73
    }
74
75
    /**
76
     * Set usesExtendedPagePartChooser.
77
     *
78
     * @param usesExtendedPagePartChooser the value to set
79
     */
80
    public function setUsesExtendedPagePartChooser($usesExtendedPagePartChooser)
81
    {
82
        $this->usesExtendedPagePartChooser = $usesExtendedPagePartChooser;
0 ignored issues
show
Documentation Bug introduced by
It seems like $usesExtendedPagePartChooser of type object<Kunstmaan\PagePar...dle\Twig\Extension\the> is incompatible with the declared type boolean of property $usesExtendedPagePartChooser.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
83
    }
84
}
85