Skip to content

Commit

Permalink
Merge branch '4.x' of https://github.com/craftcms/cms into 5.x
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonkelly committed Dec 2, 2024
2 parents c89aea3 + 3a34393 commit 00a6feb
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 30 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 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))
Expand Down
12 changes: 4 additions & 8 deletions src/elements/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
12 changes: 4 additions & 8 deletions src/elements/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
24 changes: 10 additions & 14 deletions src/elements/Entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
)));
Expand Down

0 comments on commit 00a6feb

Please sign in to comment.