mirror of
https://github.com/silverstripe/silverstripe-spamprotection.git
synced 2024-10-22 14:05:59 +02:00
Use array_map on its own in validateFieldand remove not needed array_column declaration
Use array_map on its own in validateField and remove not needed array_column declaration
This commit is contained in:
parent
74af26deb8
commit
049cddc5f4
@ -112,17 +112,14 @@ if (class_exists('EditableFormField')) {
|
|||||||
|
|
||||||
public function validateField($data, $form)
|
public function validateField($data, $form)
|
||||||
{
|
{
|
||||||
// In case you dont have this function in your php - primitive version
|
|
||||||
if (!function_exists("array_column")) {
|
|
||||||
function array_column($array, $column_name) {
|
|
||||||
return array_map(function ($element) use ($column_name) {
|
|
||||||
return $element[$column_name];
|
|
||||||
}, $array);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!$formField->validate($form->getValidator())) {
|
if (!$formField->validate($form->getValidator())) {
|
||||||
$errorArray = $form->getValidator()->getErrors();
|
$errorArray = $form->getValidator()->getErrors();
|
||||||
$errorText = $errorArray[array_search($this->Name, array_column($errorArray, 'fieldName'))]['message'];
|
|
||||||
|
$map = array_map(function ($element) {
|
||||||
|
return $element['fieldName'];
|
||||||
|
}, $errorArray);
|
||||||
|
|
||||||
|
$errorText = $errorArray[array_search($this->Name, $map)]['message'];
|
||||||
$form->addErrorMessage($this->Name, $errorText, 'error', false);
|
$form->addErrorMessage($this->Name, $errorText, 'error', false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user