From 049cddc5f4e7f3c693761f2dde8b3a1e3d2c25d4 Mon Sep 17 00:00:00 2001 From: tazzydemon Date: Tue, 8 Dec 2015 12:05:21 +1300 Subject: [PATCH] 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 --- code/EditableSpamProtectionField.php | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/code/EditableSpamProtectionField.php b/code/EditableSpamProtectionField.php index 036c27b..1a871f0 100644 --- a/code/EditableSpamProtectionField.php +++ b/code/EditableSpamProtectionField.php @@ -112,17 +112,14 @@ if (class_exists('EditableFormField')) { 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())) { $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); } }