diff --git a/CHANGELOG.md b/CHANGELOG.md index 41ce2a71185..bc2eed5a487 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +- Fixed a bug where asset, category, and entry sources defined by the `EVENT_REGISTER_SOURCES` event didn’t have any custom fields available to them, unless the `EVENT_REGISTER_FIELD_LAYOUTS` event was also used to define the available field layouts for the event-defined source. ([#16256](https://github.com/craftcms/cms/discussions/16256)) + +## 5.5.4 - 2024-12-02 + - Reduced the likelihood of a deadlock error occurring when updating search indexes. ([#15221](https://github.com/craftcms/cms/issues/15221)) - The PHP Info utility is no longer shown in environments where the `phpinfo()` function is disabled. ([#16229](https://github.com/craftcms/cms/pull/16229)) - “View” buttons within element indexes are now disabled when the selected view mode has no applicable settings. ([#16242](https://github.com/craftcms/cms/pull/16242)) diff --git a/src/config/app.php b/src/config/app.php index 54ac3d44dc0..3d3fa2118f6 100644 --- a/src/config/app.php +++ b/src/config/app.php @@ -3,7 +3,7 @@ return [ 'id' => 'CraftCMS', 'name' => 'Craft CMS', - 'version' => '5.5.3', + 'version' => '5.5.4', 'schemaVersion' => '5.6.0.1', 'minVersionRequired' => '4.5.0', 'basePath' => dirname(__DIR__), // Defines the @app alias diff --git a/src/elements/Asset.php b/src/elements/Asset.php index 90ff6024c7f..f45b35702bf 100644 --- a/src/elements/Asset.php +++ b/src/elements/Asset.php @@ -447,14 +447,10 @@ public static function sourcePath(string $sourceKey, string $stepKey, ?string $c */ protected static function defineFieldLayouts(?string $source): array { - if ($source !== null) { - $volumes = []; - if (preg_match('/^volume:(.+)$/', $source, $matches)) { - $volume = Craft::$app->getVolumes()->getVolumeByUid($matches[1]); - if ($volume) { - $volumes[] = $volume; - } - } + if ($source !== null && preg_match('/^volume:(.+)$/', $source, $matches)) { + $volumes = array_filter([ + Craft::$app->getVolumes()->getVolumeByUid($matches[1]), + ]); } else { $volumes = Craft::$app->getVolumes()->getAllVolumes(); } diff --git a/src/elements/Category.php b/src/elements/Category.php index cff3c51739c..a1276195f2f 100644 --- a/src/elements/Category.php +++ b/src/elements/Category.php @@ -200,14 +200,10 @@ protected static function defineSources(string $context): array */ protected static function defineFieldLayouts(?string $source): array { - if ($source !== null) { - $groups = []; - if (preg_match('/^group:(.+)$/', $source, $matches)) { - $group = Craft::$app->getCategories()->getGroupByUid($matches[1]); - if ($group) { - $groups[] = $group; - } - } + if ($source !== null && preg_match('/^group:(.+)$/', $source, $matches)) { + $groups = array_filter([ + Craft::$app->getCategories()->getGroupByUid($matches[1]), + ]); } else { $groups = Craft::$app->getCategories()->getAllGroups(); } diff --git a/src/elements/Entry.php b/src/elements/Entry.php index b04cbad5fa2..63936735824 100644 --- a/src/elements/Entry.php +++ b/src/elements/Entry.php @@ -371,21 +371,17 @@ public static function modifyCustomSource(array $config): array */ protected static function defineFieldLayouts(?string $source): array { - if ($source !== null) { - if ($source === '*') { - $sections = Craft::$app->getEntries()->getAllSections(); - } elseif ($source === 'singles') { - $sections = Craft::$app->getEntries()->getSectionsByType(Section::TYPE_SINGLE); - } else { - $sections = []; - if (preg_match('/^section:(.+)$/', $source, $matches)) { - $section = Craft::$app->getEntries()->getSectionByUid($matches[1]); - if ($section) { - $sections[] = $section; - } - } - } + if ($source === '*') { + $sections = Craft::$app->getEntries()->getAllSections(); + } elseif ($source === 'singles') { + $sections = Craft::$app->getEntries()->getSectionsByType(Section::TYPE_SINGLE); + } elseif ($source !== null && preg_match('/^section:(.+)$/', $source, $matches)) { + $sections = array_filter([ + Craft::$app->getEntries()->getSectionByUid($matches[1]), + ]); + } + if (isset($sections)) { $entryTypes = array_values(array_unique(array_merge( ...array_map(fn(Section $section) => $section->getEntryTypes(), $sections), ))); diff --git a/src/templates/_layouts/elementindex.twig b/src/templates/_layouts/elementindex.twig index 3932e438bc0..72c23a06218 100644 --- a/src/templates/_layouts/elementindex.twig +++ b/src/templates/_layouts/elementindex.twig @@ -33,8 +33,6 @@ }) %} {% endif %} -{% set canHaveDrafts = canHaveDrafts ?? elementInstance.hasDrafts() %} - {% block sidebar %} {% if sources is not empty %} {{ tag('a', { diff --git a/src/web/View.php b/src/web/View.php index ff34fb149ef..532b7c9ad08 100644 --- a/src/web/View.php +++ b/src/web/View.php @@ -2417,6 +2417,7 @@ private function _prepareElementIndexVariables(array &$context): null $context['elementDisplayName'] = $elementType::displayName(); $context['elementPluralDisplayName'] = $elementType::pluralDisplayName(); + $context['canHaveDrafts'] ??= $elementType::hasDrafts(); return null; }