From ef2caed9c8d80113eb54657246fcb7828835722c Mon Sep 17 00:00:00 2001 From: iglocska Date: Thu, 22 Aug 2024 12:27:11 +0200 Subject: [PATCH] fix: [metafield limitation] fixes - correctly show error messages on user creation when limits are hit - fixed a bug that cause users from being uncreatable even due to a hit limitation, even if the current user wouldn't influence said limitation --- src/Controller/Component/CRUDComponent.php | 4 ++-- src/Model/Table/UsersTable.php | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/Controller/Component/CRUDComponent.php b/src/Controller/Component/CRUDComponent.php index e6d6f6c..9330740 100644 --- a/src/Controller/Component/CRUDComponent.php +++ b/src/Controller/Component/CRUDComponent.php @@ -526,10 +526,10 @@ class CRUDComponent extends Component if (!empty($errors)) { if (count($errors) == 1) { $field = array_keys($errors)[0]; - $fieldError = implode(', ', array_values($errors[$field])); + $fieldError = json_encode($errors[$field]); $validationMessage = __('{0}: {1}', $field, $fieldError); } else { - $validationMessage = __('There has been validation issues with multiple fields'); + $validationMessage = __('There has been validation issues with multiple fields: {0}', json_encode($errors)); } } return $validationMessage; diff --git a/src/Model/Table/UsersTable.php b/src/Model/Table/UsersTable.php index ddccff6..14c4750 100644 --- a/src/Model/Table/UsersTable.php +++ b/src/Model/Table/UsersTable.php @@ -111,7 +111,6 @@ class UsersTable extends AppTable } } } - if (!$enabled && !empty($entity->_metafields_to_delete)) { foreach ($entity->_metafields_to_delete as $metaFieldToDelete) { if ($metaFieldToDelete['field'] === $permission_name) { @@ -120,7 +119,7 @@ class UsersTable extends AppTable } } - if ($valueToCompareTo > $permission_data['limit']) { + if ($enabled && $valueToCompareTo > $permission_data['limit']) { return [ $permission_name => __( @@ -202,7 +201,7 @@ class UsersTable extends AppTable foreach ($permissionRestrictionCheck as $permission_name => $errors) { foreach ($entity->meta_fields as $i => $metaField) { if ($metaField['field'] === $permission_name) { - $entity->meta_fields[$i]->setErrors(['value' => $errors]); + $entity->setErrors(['meta_fields' => [$permission_name => $errors]]); } } }