diff --git a/CHANGELOG.md b/CHANGELOG.md index 60cb12922a7..bc2eed5a487 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Release Notes for Craft CMS 5 +## 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)) 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), )));