Skip to content

Commit

Permalink
Fallback to all field layouts for event-defined sources
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonkelly committed Dec 2, 2024
1 parent cfd7b6e commit 3a34393
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 21 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Release Notes for Craft CMS 4

## 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))

## 4.13.4 - 2024-12-02

- Reduced the likelihood of a deadlock error occurring when updating search indexes. ([#15221](https://github.com/craftcms/cms/issues/15221))
Expand Down
14 changes: 7 additions & 7 deletions src/elements/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -442,14 +442,14 @@ public static function sourcePath(string $sourceKey, string $stepKey, ?string $c
*/
protected static function defineFieldLayouts(string $source): array
{
$fieldLayouts = [];
if (
preg_match('/^volume:(.+)$/', $source, $matches) &&
($volume = Craft::$app->getVolumes()->getVolumeByUid($matches[1]))
) {
$fieldLayouts[] = $volume->getFieldLayout();
if (preg_match('/^volume:(.+)$/', $source, $matches)) {
$volume = Craft::$app->getVolumes()->getVolumeByUid($matches[1]);
return array_filter([
$volume?->getFieldLayout(),
]);
}
return $fieldLayouts;

return parent::defineFieldLayouts($source);
}

/**
Expand Down
16 changes: 8 additions & 8 deletions src/elements/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,14 +212,14 @@ protected static function defineSources(string $context): array
*/
protected static function defineFieldLayouts(string $source): array
{
$fieldLayouts = [];
if (
preg_match('/^group:(.+)$/', $source, $matches) &&
($group = Craft::$app->getCategories()->getGroupByUid($matches[1]))
) {
$fieldLayouts[] = $group->getFieldLayout();
}
return $fieldLayouts;
if (preg_match('/^group:(.+)$/', $source, $matches)) {
$group = Craft::$app->getCategories()->getGroupByUid($matches[1]);
return array_filter([
$group?->getFieldLayout(),
]);
}

return parent::defineFieldLayouts($source);
}

/**
Expand Down
12 changes: 6 additions & 6 deletions src/elements/Entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -350,16 +350,16 @@ public static function modifyCustomSource(array $config): array
protected static function defineFieldLayouts(string $source): array
{
// Get all the sections covered by this source
$sections = [];
if ($source === '*') {
$sections = Craft::$app->getSections()->getAllSections();
} elseif ($source === 'singles') {
$sections = Craft::$app->getSections()->getSectionsByType(Section::TYPE_SINGLE);
} elseif (
preg_match('/^section:(.+)$/', $source, $matches) &&
$section = Craft::$app->getSections()->getSectionByUid($matches[1])
) {
$sections = [$section];
} elseif (preg_match('/^section:(.+)$/', $source, $matches)) {
$sections = array_filter([
Craft::$app->getSections()->getSectionByUid($matches[1]),
]);
} else {
return parent::defineFieldLayouts($source);
}

$fieldLayouts = [];
Expand Down

0 comments on commit 3a34393

Please sign in to comment.