From ac0f543c6c69b9104cb797e4e138cfee85d0135f Mon Sep 17 00:00:00 2001 From: Iwona Just Date: Thu, 19 Sep 2024 13:23:52 +0100 Subject: [PATCH 1/2] validate handle of the new entry type --- src/console/controllers/SectionsController.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/console/controllers/SectionsController.php b/src/console/controllers/SectionsController.php index cb251fede0e..df92a4c22b0 100644 --- a/src/console/controllers/SectionsController.php +++ b/src/console/controllers/SectionsController.php @@ -144,18 +144,18 @@ public function actionCreate(): int 'previewTargets' => [], ]); - $validateAttribute = function($attributes, ?string &$error = null): bool { - $section = new Section($attributes); + $validateAttribute = function($attributes, ?string &$error = null, string $class = Section::class): bool { + $model = new $class($attributes); $attributeNames = array_keys($attributes); - if (!$section->validate($attributeNames)) { - $error = $section->getFirstError($attributeNames[0]); + if (!$model->validate($attributeNames)) { + $error = $model->getFirstError($attributeNames[0]); return false; } return true; }; - $getDefaultAttribute = function(string $attribute, string $value) use ($validateAttribute): ?string { - if ($validateAttribute([$attribute => $value])) { + $getDefaultAttribute = function(string $attribute, string $value, string $class = Section::class) use ($validateAttribute): ?string { + if ($validateAttribute([$attribute => $value], class: $class)) { return $value; } return null; @@ -292,7 +292,8 @@ public function actionCreate(): int 'default' => Inflector::singularize($section->name), ]); $entryType->handle = $this->prompt('Entry type handle:', [ - 'default' => StringHelper::toHandle($entryType->name), + 'validator' => fn(string $handle, ?string & $error = null) => $validateAttribute(compact('handle'), $error, EntryType::class), + 'default' => $getDefaultAttribute('handle', StringHelper::toHandle($entryType->name), EntryType::class), ]); $saveEntryType = true; } From b37df5a1226edfe9d76b45f0e2e1e4b86b393da3 Mon Sep 17 00:00:00 2001 From: brandonkelly Date: Fri, 20 Sep 2024 16:03:38 -0700 Subject: [PATCH 2/2] Release note [ci skip] --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 94a1c1a2077..17e977d32df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - Fixed a bug where custom fields’ `required` properties were always `false`. ([#15752](https://github.com/craftcms/cms/issues/15752)) - Fixed a bug where it wasn’t possible to save nested entries via the `entries/save-entry` controller action. ([#15737](https://github.com/craftcms/cms/issues/15737)) - Fixed a bug where hyperlinks in Link field inputs could wrap unnecessarily. ([#15738](https://github.com/craftcms/cms/issues/15738)) +- Fixed an error that occurred when running the `entrify/global-set` command. ([#15746](https://github.com/craftcms/cms/issues/15746)) ## 5.4.4 - 2024-09-14