1 | <?php |
||
25 | class InputMaskFormTwigExtension extends AbstractFormTwigExtension { |
||
26 | |||
27 | /** |
||
28 | * Service name. |
||
29 | * |
||
30 | * @var string |
||
31 | */ |
||
32 | const SERVICE_NAME = "webeweb.bundle.bootstrapbundle.twig.extension.form.inputmask"; |
||
33 | |||
34 | /** |
||
35 | * Constructor. |
||
36 | * |
||
37 | * @param RouterInterface $router The router. |
||
38 | * @param TranslatorInterface $translator The translator. |
||
39 | */ |
||
40 | public function __construct(RouterInterface $router, TranslatorInterface $translator) { |
||
43 | |||
44 | /** |
||
45 | * Displays a Bootstrap input mask. |
||
46 | * |
||
47 | * @param array $args The arguments. |
||
48 | * @return string Returns the Bootstrap input mask. |
||
49 | */ |
||
50 | public function bootstrapInputMaskFunction(array $args = []) { |
||
53 | |||
54 | /** |
||
55 | * Displays a Bootstrap input mask "Phone number". |
||
56 | * |
||
57 | * @param array $args The arguments. |
||
58 | * @return string Returns the Bootstrap input mask "Phone number". |
||
59 | */ |
||
60 | public function bootstrapInputMaskPhoneNumberFunction(array $args = []) { |
||
61 | return $this->bootstrapInputMask(ArrayUtility::get($args, "selector"), ArrayUtility::get($args, "scriptTag", false), $this->prepareOptions($args, "99 99 99 99 99")); |
||
62 | } |
||
63 | |||
64 | /** |
||
65 | * Displays a Bootstrap input mask "SIRET number". |
||
66 | * |
||
67 | * @param array $args The arguments. |
||
68 | * @return string Returns the Bootstrap input mask "SIRET number". |
||
69 | */ |
||
70 | public function bootstrapInputMaskSIRETNumberFunction(array $args = []) { |
||
71 | return $this->bootstrapInputMask(ArrayUtility::get($args, "selector"), ArrayUtility::get($args, "scriptTag", false), $this->prepareOptions($args, "999 999 999 99999")); |
||
72 | } |
||
73 | |||
74 | /** |
||
75 | * Displays a Bootstrap input mask "Social security number". |
||
76 | * |
||
77 | * @param array $args The arguments. |
||
78 | * @return string Returns the Bootstrap input mask "Social security number". |
||
79 | */ |
||
80 | public function bootstrapInputMaskSocialSecurityNumberFunction(array $args = []) { |
||
81 | return $this->bootstrapInputMask(ArrayUtility::get($args, "selector"), ArrayUtility::get($args, "scriptTag", false), $this->prepareOptions($args, "9 99 99 99 999 999 99")); |
||
82 | } |
||
83 | |||
84 | /** |
||
85 | * Displays a Bootstrap input mask "Time 12 hour". |
||
86 | * |
||
87 | * @param array $args The arguments. |
||
88 | * @return string Returns the Bootstrap input mask "Time 12 hour". |
||
89 | */ |
||
90 | public function bootstrapInputMaskTime12Function(array $args = []) { |
||
91 | return $this->bootstrapInputMask(ArrayUtility::get($args, "selector"), ArrayUtility::get($args, "scriptTag", false), array_merge($this->prepareOptions($args, "hh:mm t"), ["alias" => "time12", "hourFormat" => "12", "placeholder" => "__:__ _m"])); |
||
92 | } |
||
93 | |||
94 | /** |
||
95 | * Displays a Bootstrap input mask "Time 24 hour". |
||
96 | * |
||
97 | * @param array $args The arguments. |
||
98 | * @return string Returns the Bootstrap input mask "Time 24 hour". |
||
99 | */ |
||
100 | public function bootstrapInputMaskTime24Function(array $args = []) { |
||
101 | return $this->bootstrapInputMask(ArrayUtility::get($args, "selector"), ArrayUtility::get($args, "scriptTag", false), array_merge($this->prepareOptions($args, "hh:mm"), ["alias" => "time24", "hourFormat" => "24", "placeholder" => "__:__ _m"])); |
||
102 | } |
||
103 | |||
104 | /** |
||
105 | * Displays a Bootstrap input mask "VAT number". |
||
106 | * |
||
107 | * @param array $args The arguments. |
||
108 | * @return string Returns the Bootstrap input mask "VAT number". |
||
109 | */ |
||
110 | public function bootstrapInputMaskVATNumberFunction(array $args = []) { |
||
111 | return $this->bootstrapInputMask(ArrayUtility::get($args, "selector"), ArrayUtility::get($args, "scriptTag", false), $this->prepareOptions($args, "**999 999 999 99")); |
||
112 | } |
||
113 | |||
114 | /** |
||
115 | * Get the Twig functions. |
||
116 | * |
||
117 | * @return array Returns the Twig functions. |
||
118 | */ |
||
119 | public function getFunctions() { |
||
130 | |||
131 | /** |
||
132 | * Prepare the arguments. |
||
133 | * |
||
134 | * @param array $args The arguments. |
||
135 | * @param string $defaultMask |
||
136 | * @return array Returns the prepared arguments. |
||
137 | */ |
||
138 | private function prepareOptions(array $args = [], $defaultMask) { |
||
153 | |||
154 | } |
||
155 |