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 Twig_SimpleFunction; |
15
|
|
|
use WBW\Library\Core\Utility\ArrayUtility; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Input mask form Twig Extension. |
19
|
|
|
* |
20
|
|
|
* @author webeweb <https://github.com/webeweb/> |
21
|
|
|
* @package WBW\Bundle\BootstrapBundle\Twig\Extension\Form |
22
|
|
|
* @final |
23
|
|
|
*/ |
24
|
|
|
final class InputMaskFormTwigExtension extends AbstractFormTwigExtension { |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Service name. |
28
|
|
|
* |
29
|
|
|
* @var string |
30
|
|
|
*/ |
31
|
|
|
const SERVICE_NAME = "webeweb.bundle.bootstrapbundle.twig.extension.form.inputmask"; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Displays a phone number input mask. |
35
|
|
|
* |
36
|
|
|
* @param array $args The arguments. |
37
|
|
|
* @return string Returns the phone number input mask. |
38
|
|
|
*/ |
39
|
|
|
public function bootstrapPhoneNumberInputMaskFunction(array $args = []) { |
40
|
|
|
return $this->bootstrapInputMask(ArrayUtility::get($args, "selector"), ["autoUnmask" => true, "removeMaskOnSubmit" => true, "mask" => "99 99 99 99 99", "placeholder" => "__ __ __ __ __"]); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Displays a SIRET number input mask. |
45
|
|
|
* |
46
|
|
|
* @param array $args The arguments. |
47
|
|
|
* @return string Returns the SIRET number input mask. |
48
|
|
|
*/ |
49
|
|
|
public function bootstrapSIRETNumberInputMaskFunction(array $args = []) { |
50
|
|
|
return $this->bootstrapInputMask(ArrayUtility::get($args, "selector"), ["autoUnmask" => true, "removeMaskOnSubmit" => true, "mask" => "999 999 999 99999", "placeholder" => "___ ___ ___ ___"]); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Displays a social security number input mask. |
55
|
|
|
* |
56
|
|
|
* @param array $args The arguments. |
57
|
|
|
* @return string Returns the social security number input mask. |
58
|
|
|
*/ |
59
|
|
|
public function bootstrapSocialSecurityNumberInputMaskFunction(array $args = []) { |
60
|
|
|
return $this->bootstrapInputMask(ArrayUtility::get($args, "selector"), ["autoUnmask" => true, "removeMaskOnSubmit" => true, "mask" => "9 99 99 99 999 999 99", "placeholder" => "_ __ __ __ ___ ___ __"]); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Displays a VAT number input mask. |
65
|
|
|
* |
66
|
|
|
* @param array $args The arguments. |
67
|
|
|
* @return string Returns the VAT number input mask. |
68
|
|
|
*/ |
69
|
|
|
public function bootstrapVATNumberInputMaskFunction(array $args = []) { |
70
|
|
|
return $this->bootstrapInputMask(ArrayUtility::get($args, "selector"), ["autoUnmask" => true, "removeMaskOnSubmit" => true, "mask" => "**999 999 999 99", "placeholder" => "_____ ___ ___ ___ __"]); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Get the Twig functions. |
75
|
|
|
* |
76
|
|
|
* @return array Returns the Twig functions. |
77
|
|
|
*/ |
78
|
|
|
public function getFunctions() { |
79
|
|
|
return [ |
80
|
|
|
new Twig_SimpleFunction("bootstrapPhoneNumberInputMask", [$this, "bootstrapPhoneNumberInputMaskFunction"], ["is_safe" => ["html"]]), |
81
|
|
|
new Twig_SimpleFunction("bootstrapSIRETNumberInputMask", [$this, "bootstrapSIRETNumberInputMaskFunction"], ["is_safe" => ["html"]]), |
82
|
|
|
new Twig_SimpleFunction("bootstrapSocialSecurityNumberInputMask", [$this, "bootstrapSocialSecurityNumberInputMaskFunction"], ["is_safe" => ["html"]]), |
83
|
|
|
new Twig_SimpleFunction("bootstrapVATNumberInputMask", [$this, "bootstrapVATNumberInputMaskFunction"], ["is_safe" => ["html"]]), |
84
|
|
|
]; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
} |
88
|
|
|
|