1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the core-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\CoreBundle\Twig\Extension\Plugin; |
13
|
|
|
|
14
|
|
|
use Twig_Environment; |
15
|
|
|
use WBW\Bundle\CoreBundle\Twig\Extension\AbstractTwigExtension; |
16
|
|
|
use WBW\Bundle\CoreBundle\Twig\Extension\RendererTwigExtension; |
17
|
|
|
use WBW\Bundle\CoreBundle\Twig\Extension\RendererTwigExtensionTrait; |
18
|
|
|
use WBW\Library\Core\Argument\StringHelper; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Abstract jQuery input mask Twig extension. |
22
|
|
|
* |
23
|
|
|
* @author webeweb <https://github.com/webeweb/> |
24
|
|
|
* @package WBW\Bundle\Core\Twig\Extension\Plugin |
25
|
|
|
* @abstract |
26
|
|
|
*/ |
27
|
|
|
abstract class AbstractJQueryInputMaskTwigExtension extends AbstractTwigExtension { |
28
|
|
|
|
29
|
|
|
use RendererTwigExtensionTrait; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Constructor. |
33
|
|
|
* |
34
|
|
|
* @param Twig_Environment $twigEnvironment The twig environment. |
35
|
|
|
* @param RendererTwigExtension $rendererTwigExtension The renderer Twig extension. |
36
|
|
|
*/ |
37
|
|
|
protected function __construct(Twig_Environment $twigEnvironment, RendererTwigExtension $rendererTwigExtension) { |
38
|
|
|
parent::__construct($twigEnvironment); |
39
|
|
|
$this->setRendererTwigExtension($rendererTwigExtension); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Displays a jQuery input mask. |
44
|
|
|
* |
45
|
|
|
* @param string $selector The selector. |
46
|
|
|
* @param string $mask The mask. |
47
|
|
|
* @param array $options The options. |
48
|
|
|
* @param bool $scriptTag Script tag ? |
49
|
|
|
* @return string Returns the jQuery input mask. |
50
|
|
|
*/ |
51
|
|
|
protected function jQueryInputMask($selector, $mask, array $options, $scriptTag) { |
52
|
|
|
|
53
|
|
|
// Initialize the template. |
54
|
|
|
$template = "$('%selector%').inputmask(\"%mask%\",%arguments%);"; |
55
|
|
|
|
56
|
|
|
// Initialize the parameters. |
57
|
|
|
$innerHTML = StringHelper::replace($template, ["%selector%", "%mask%", "%arguments%"], [$selector, $mask, json_encode($options)]); |
58
|
|
|
|
59
|
|
|
// Return the HTML |
60
|
|
|
if (true === $scriptTag) { |
61
|
|
|
return $this->getRendererTwigExtension()->coreScriptFilter($innerHTML); |
62
|
|
|
} |
63
|
|
|
return $innerHTML; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
} |
67
|
|
|
|