Last active
March 7, 2017 18:26
-
-
Save ummdorian/eaece93165df0bdd6546b07614e955e4 to your computer and use it in GitHub Desktop.
Fix for Drupal 8 decimal field validation fix re: "invalid number error" addressed here: https://www.drupal.org/node/2230909
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function hook_form_BASE_FORM_ID_alter()(array &$form, FormStateInterface $form_state){ | |
$form['#validate'][] = 'module_remove_decimal_errors'; | |
} | |
function module_remove_decimal_errors(array &$form, FormStateInterface $form_state) { | |
$errorsToRemove = array('field_your_field][0][value','field_your_other_field][0][value'); | |
$errorsToKeep = array(); | |
$currentErrors = $form_state->getErrors(); | |
foreach($currentErrors as $error_key => $errorObject){ | |
if(!in_array($error_key,$errorsToRemove)){ | |
$errorsToKeep[$error_key] = $errorObject; | |
} | |
} | |
$form_state->clearErrors(); | |
foreach($errorsToKeep as $errorKeyToKeep => $errorToKeep){ | |
preg_match('/^([^\]]*)/',$errorKeyToKeep,$thisErrorFieldName); | |
$form_state->setErrorByName($thisErrorFieldName[0], strip_tags($errorToKeep->render())); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment