Skip to content
Snippets Groups Projects

Fixed bug to make it possible to save "0" as a mask value.

Merged Christophe Goffin requested to merge issue/mask-3335413:3335413-can-not-save into 2.0.x
2 files
+ 14
12
Compare changes
  • Side-by-side
  • Inline
Files
2
+ 12
10
@@ -27,21 +27,23 @@ class ElementHelper implements ElementHelperInterface {
@@ -27,21 +27,23 @@ class ElementHelper implements ElementHelperInterface {
* {@inheritdoc}
* {@inheritdoc}
*/
*/
public static function processElement(array &$element, FormStateInterface $form_state, array &$complete_form) {
public static function processElement(array &$element, FormStateInterface $form_state, array &$complete_form) {
if (!empty($element['#mask']['value'])) {
if (isset($element['#mask']['value']) && $element['#mask']['value'] !== '') {
// Adds HTML attributes to the element.
// Adds HTML attributes to the element.
foreach ($element['#mask'] as $option => $value) {
foreach ($element['#mask'] as $option => $value) {
if (!empty($value)) {
if ($option !== 'value' && empty($value)) {
// Appends the option name to the attribute name.
continue;
$attr = "data-mask-$option";
}
// Except for the value, all other options are booleans.
// Appends the option name to the attribute name.
if ($option != 'value') {
$attr = "data-mask-$option";
$value = $value ? 'true' : 'false';
}
// Adds the attribute.
// Except for the value, all other options are booleans.
$element['#attributes'][$attr] = is_string($value) ? $value : (string) $value;
if ($option != 'value') {
 
$value = $value ? 'true' : 'false';
}
}
 
 
// Adds the attribute.
 
$element['#attributes'][$attr] = is_string($value) ? $value : (string) $value;
}
}
// Attaches the JavaScript library and settings.
// Attaches the JavaScript library and settings.
Loading