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