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\Asset; |
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
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Abstract jQuery input mask Twig extension. |
21
|
|
|
* |
22
|
|
|
* @author webeweb <https://github.com/webeweb/> |
23
|
|
|
* @package WBW\Bundle\Core\Twig\Extension\Plugin |
24
|
|
|
* @abstract |
25
|
|
|
*/ |
26
|
|
|
abstract class AbstractJQueryInputMaskTwigExtension extends AbstractTwigExtension { |
27
|
|
|
|
28
|
|
|
use RendererTwigExtensionTrait; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Constructor. |
32
|
|
|
* |
33
|
|
|
* @param Environment $twigEnvironment The Twig environment. |
34
|
|
|
* @param RendererTwigExtension $rendererTwigExtension The renderer Twig extension. |
35
|
|
|
*/ |
36
|
|
|
public function __construct(Environment $twigEnvironment, RendererTwigExtension $rendererTwigExtension) { |
37
|
|
|
parent::__construct($twigEnvironment); |
38
|
|
|
$this->setRendererTwigExtension($rendererTwigExtension); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Displays a jQuery input mask. |
43
|
|
|
* |
44
|
|
|
* @param string $selector The selector. |
45
|
|
|
* @param string $mask The mask. |
46
|
|
|
* @param array $options The options. |
47
|
|
|
* @param bool $scriptTag Script tag ? |
48
|
|
|
* @return string Returns the jQuery input mask. |
49
|
|
|
*/ |
50
|
|
|
protected function jQueryInputMask($selector, $mask, array $options, $scriptTag) { |
51
|
|
|
|
52
|
|
|
$template = "$('%selector%').inputmask(\"%mask%\",%arguments%);"; |
53
|
|
|
|
54
|
|
|
$innerHTML = str_replace(["%selector%", "%mask%", "%arguments%"], [$selector, $mask, json_encode($options)], $template); |
55
|
|
|
|
56
|
|
|
if (true === $scriptTag) { |
57
|
|
|
return $this->getRendererTwigExtension()->coreScriptFilter($innerHTML); |
58
|
|
|
} |
59
|
|
|
return $innerHTML; |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|