Skip to content

Commit d95d716

Browse files
authored
Merge pull request #1675 from craftcms/bugfix/1674-getting-layout-by-id
don't freak out if there's no layout
2 parents 5878d24 + 86d191a commit d95d716

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

src/fields/Categories.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,11 @@ public static function getMatchFields(FeedModel $feed, ?BaseRelationField $field
241241
if (!$categoryGroup) {
242242
return FieldHelper::getAllUniqueIdFields();
243243
}
244-
$fieldLayout = Craft::$app->getFields()->getLayoutById($categoryGroup->fieldLayoutId);
244+
245+
$fieldLayout = null;
246+
if ($categoryGroup->fieldLayoutId) {
247+
$fieldLayout = Craft::$app->getFields()->getLayoutById($categoryGroup->fieldLayoutId);
248+
}
245249
if (!$fieldLayout) {
246250
return FieldHelper::getAllUniqueIdFields();
247251
}

src/fields/Entries.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,11 @@ public static function getMatchFields(FeedModel $feed, ?BaseRelationField $field
268268
return FieldHelper::getAllUniqueIdFields();
269269
}
270270

271-
$fieldLayout = Craft::$app->getFields()->getLayoutById($entryType->fieldLayoutId);
271+
$fieldLayout = null;
272+
if ($entryType->fieldLayoutId) {
273+
$fieldLayout = Craft::$app->getFields()->getLayoutById($entryType->fieldLayoutId);
274+
}
275+
272276
if (!$fieldLayout) {
273277
return FieldHelper::getAllUniqueIdFields();
274278
}
@@ -294,8 +298,12 @@ public static function getMatchFields(FeedModel $feed, ?BaseRelationField $field
294298
$entryTypes = Collection::make($entryTypes)->keyBy('id');
295299

296300
foreach ($entryTypes as $entryType) {
297-
$fieldLayout = Craft::$app->getFields()->getLayoutById($entryType->fieldLayoutId);
298-
$allowedFields = [...$allowedFields, ...$fieldLayout->getCustomFields()];
301+
if ($entryType->fieldLayoutId) {
302+
$fieldLayout = Craft::$app->getFields()->getLayoutById($entryType->fieldLayoutId);
303+
if ($fieldLayout) {
304+
$allowedFields = [...$allowedFields, ...$fieldLayout->getCustomFields()];
305+
}
306+
}
299307
}
300308

301309
// if there's a custom source in the mix, we should add all the fields too

0 commit comments

Comments
 (0)