These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | /* |
||
4 | * This file is part of the bootstrap-bundle package. |
||
5 | * |
||
6 | * (c) 2018 WEBEWEB |
||
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 WBW\Bundle\BootstrapBundle\Twig\Extension\Utility; |
||
13 | |||
14 | use Symfony\Component\Translation\TranslatorInterface; |
||
15 | use Twig_Environment; |
||
16 | use Twig_SimpleFunction; |
||
17 | use WBW\Bundle\BootstrapBundle\Twig\Extension\CSS\ButtonTwigExtension; |
||
18 | use WBW\Bundle\BootstrapBundle\Twig\Extension\CSS\ButtonTwigExtensionTrait; |
||
19 | use WBW\Library\Core\Argument\ArrayHelper; |
||
20 | |||
21 | /** |
||
22 | * Form button Twig extension. |
||
23 | * |
||
24 | * @author webeweb <https://github.com/webeweb/> |
||
25 | * @package WBW\Bundle\BootstrapBundle\Twig\Extension\Utility |
||
26 | */ |
||
27 | class FormButtonTwigExtension extends AbstractUtilityTwigExtension { |
||
28 | |||
29 | use ButtonTwigExtensionTrait; |
||
30 | |||
31 | /** |
||
32 | * Service name. |
||
33 | * |
||
34 | * @var string |
||
35 | */ |
||
36 | const SERVICE_NAME = "webeweb.bootstrap.twig.extension.utility.form_button"; |
||
37 | |||
38 | /** |
||
39 | * Constructor. |
||
40 | * |
||
41 | * @param Twig_Environment $twigEnvironment The Twig environment. |
||
42 | * @param TranslatorInterface $translator The translator. |
||
43 | * @param ButtonTwigExtension $extension The button component Twig extension. |
||
44 | */ |
||
45 | public function __construct(Twig_Environment $twigEnvironment, TranslatorInterface $translator, ButtonTwigExtension $extension) { |
||
46 | parent::__construct($twigEnvironment, $translator); |
||
47 | $this->setButtonTwigExtension($extension); |
||
48 | } |
||
49 | |||
50 | /** |
||
51 | * Displays a Bootstrap form button "Cancel". |
||
52 | * |
||
53 | * @param array $args The arguments. |
||
54 | * @return string Returns the Bootstrap form button "Cancel". |
||
55 | */ |
||
56 | public function bootstrapFormButtonCancelFunction(array $args = []) { |
||
57 | |||
58 | // Translate the label. |
||
59 | $txt = $this->getTranslator()->trans("label.cancel", [], "BootstrapBundle"); |
||
60 | |||
61 | // Initialize the button. |
||
62 | $but = $this->getButtonTwigExtension()->bootstrapButtonDefaultFunction(["content" => $txt, "title" => $txt, "icon" => "g:remove"]); |
||
63 | |||
64 | // Return the HTML. |
||
65 | return $this->getButtonTwigExtension()->bootstrapButtonLinkFilter($but, ArrayHelper::get($args, "href", self::DEFAULT_HREF)); |
||
66 | } |
||
67 | |||
68 | /** |
||
69 | * Displays a Bootstrap form buttons "Default". |
||
70 | * |
||
71 | * @param array $args The arguments. |
||
72 | * @return string Returns the Bootstrap form button "Default". |
||
73 | */ |
||
74 | public function bootstrapFormButtonDefaultFunction(array $args = []) { |
||
75 | |||
76 | // Initialize the buttons. |
||
77 | $cancelButton = $this->bootstrapFormButtonCancelFunction(["href" => ArrayHelper::get($args, "cancel_href")]); |
||
78 | $submitButton = $this->bootstrapFormButtonSubmitFunction(); |
||
79 | |||
80 | // Return the HTML. |
||
81 | return implode(" ", [$cancelButton, $submitButton]); |
||
82 | } |
||
83 | |||
84 | /** |
||
85 | * Displays a Bootstrap form button "Submit". |
||
86 | * |
||
87 | * @return string Returns the Bootstrap form button "Submit". |
||
88 | */ |
||
89 | public function bootstrapFormButtonSubmitFunction() { |
||
90 | |||
91 | // Translate the label. |
||
92 | $txt = $this->getTranslator()->trans("label.submit", [], "BootstrapBundle"); |
||
93 | |||
94 | // Initialize the button. |
||
95 | $but = $this->getButtonTwigExtension()->bootstrapButtonPrimaryFunction(["content" => $txt, "title" => $txt, "icon" => "g:ok"]); |
||
96 | |||
97 | // Return the HTML. |
||
98 | return $this->getButtonTwigExtension()->bootstrapButtonSubmitFilter($but); |
||
99 | } |
||
100 | |||
101 | /** |
||
102 | * Get the Twig functions. |
||
103 | * |
||
104 | * @return array Returns the Twig functions. |
||
105 | */ |
||
106 | public function getFunctions() { |
||
107 | return [ |
||
108 | new Twig_SimpleFunction("bootstrapFormButtonCancel", [$this, "bootstrapFormButtonCancelFunction"], ["is_safe" => ["html"]]), |
||
0 ignored issues
–
show
|
|||
109 | new Twig_SimpleFunction("bootstrapFormButtonDefault", [$this, "bootstrapFormButtonDefaultFunction"], ["is_safe" => ["html"]]), |
||
0 ignored issues
–
show
The class
Twig_SimpleFunction has been deprecated with message: since Twig 2.7, use "Twig\TwigFunction" instead
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.
Loading history...
|
|||
110 | new Twig_SimpleFunction("bootstrapFormButtonSubmit", [$this, "bootstrapFormButtonSubmitFunction"], ["is_safe" => ["html"]]), |
||
0 ignored issues
–
show
The class
Twig_SimpleFunction has been deprecated with message: since Twig 2.7, use "Twig\TwigFunction" instead
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.
Loading history...
|
|||
111 | ]; |
||
112 | } |
||
113 | } |
||
114 |
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.