Completed
Push — master ( 695906...a2e16e )
by WEBEWEB
19:00
created

bootstrapRowButtonDeleteFunction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
cc 1
nc 1
nop 1
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
 * Table button Twig extension.
23
 *
24
 * @author webeweb <https://github.com/webeweb/>
25
 * @package WBW\Bundle\BootstrapBundle\Twig\Extension\Utility
26
 */
27
class TableButtonTwigExtension 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.table_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 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 row button "Default".
52
     *
53
     * @param array $args The arguments.
54
     * @return string Returns the Bootstrap form button "Default".
55
     */
56
    public function bootstrapRowButtonDefaultFunction(array $args = []) {
57
58
        // Initialize the buttons.
59
        $editButton   = $this->bootstrapRowButtonEditFunction(["href" => ArrayHelper::get($args, "edit_href")]);
60
        $deleteButton = $this->bootstrapRowButtonDeleteFunction(["href" => ArrayHelper::get($args, "delete_href")]);
61
62
        // Return the HTML.
63
        return implode(" ", [$editButton, $deleteButton]);
64
    }
65
66
    /**
67
     * Displays a Bootstrap row button "Delete".
68
     *
69
     * @param array $args The arguments.
70
     * @return string Returns the Bootstrap row button "Delete".
71
     */
72
    public function bootstrapRowButtonDeleteFunction(array $args = []) {
73
74
        // Translate the label.
75
        $txt = $this->getTranslator()->trans("label.delete", [], "BootstrapBundle");
76
77
        // Initialize the button.
78
        $but = $this->getButtonTwigExtension()->bootstrapButtonDangerFunction(["title" => $txt, "icon" => "g:trash"]);
79
80
        // Return the HTML.
81
        return $this->getButtonTwigExtension()->bootstrapButtonLinkFilter($but, ArrayHelper::get($args, "href", self::DEFAULT_HREF));
82
    }
83
84
    /**
85
     * Displays a Bootstrap row button "Edit".
86
     *
87
     * @param array $args The arguments.
88
     * @return string Returns the Bootstrap row button "Edit".
89
     */
90
    public function bootstrapRowButtonEditFunction(array $args = []) {
91
92
        // Translate the label.
93
        $txt = $this->getTranslator()->trans("label.edit", [], "BootstrapBundle");
94
95
        // Initialize the button.
96
        $but = $this->getButtonTwigExtension()->bootstrapButtonDefaultFunction(["title" => $txt, "icon" => "g:pencil"]);
97
98
        // Return the HTML.
99
        return $this->getButtonTwigExtension()->bootstrapButtonLinkFilter($but, ArrayHelper::get($args, "href", self::DEFAULT_HREF));
100
    }
101
102
    /**
103
     * Get the Twig functions.
104
     *
105
     * @return array Returns the Twig functions.
106
     */
107
    public function getFunctions() {
108
        return [
109
            new Twig_SimpleFunction("bootstrapRowButtonDefault", [$this, "bootstrapRowButtonDefaultFunction"], ["is_safe" => ["html"]]),
0 ignored issues
show
Deprecated Code introduced by
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("bootstrapRowButtonDelete", [$this, "bootstrapRowButtonDeleteFunction"], ["is_safe" => ["html"]]),
0 ignored issues
show
Deprecated Code introduced by
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
            new Twig_SimpleFunction("bootstrapRowButtonEdit", [$this, "bootstrapRowButtonEditFunction"], ["is_safe" => ["html"]]),
0 ignored issues
show
Deprecated Code introduced by
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...
112
        ];
113
    }
114
}
115