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\Plugin; |
13
|
|
|
|
14
|
|
|
use WBW\Bundle\BootstrapBundle\Twig\Extension\AbstractBootstrapTwigExtension; |
15
|
|
|
use WBW\Library\Core\Utility\Argument\StringUtility; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Abstract plugin Twig extension. |
19
|
|
|
* |
20
|
|
|
* @author webeweb <https://github.com/webeweb/> |
21
|
|
|
* @package WBW\Bundle\BootstrapBundle\Twig\Extension\Plugin |
22
|
|
|
* @abstract |
23
|
|
|
*/ |
24
|
|
|
abstract class AbstractPluginTwigExtension extends AbstractBootstrapTwigExtension { |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Constructor. |
28
|
|
|
*/ |
29
|
|
|
protected function __construct() { |
30
|
|
|
// NOTHING TO DO. |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Displays a Bootstrap input mask. |
35
|
|
|
* |
36
|
|
|
* @param string $selector The input mask selector. |
37
|
|
|
* @param string $mask The input mask. |
38
|
|
|
* @param boolean $scriptTag Script tag ? |
39
|
|
|
* @param array $options The input mask options. |
40
|
|
|
* @return string Returns the Bootstrap input mask. |
41
|
|
|
*/ |
42
|
|
|
protected function bootstrapInputMask($selector, $mask, $scriptTag, array $options) { |
43
|
|
|
|
44
|
|
|
// Initialize the template. |
45
|
|
|
$template = ["$('%selector%').inputmask(\"%mask%\",%arguments%);"]; |
46
|
|
|
if (true === $scriptTag) { |
47
|
|
|
array_unshift($template, "<script type=\"text/javascript\">"); |
48
|
|
|
array_push($template, "</script>"); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
// Return the HTML. |
52
|
|
|
return StringUtility::replace(implode("\n", $template), ["%selector%", "%mask%", "%arguments%"], [$selector, $mask, json_encode($options)]); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
} |
56
|
|
|
|