Skip to content

Commit 34c7f7e

Browse files
committed
Fallback to getEntryTypeById()
Fixes #16539
1 parent 40029c6 commit 34c7f7e

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
- Fixed a bug where SSO logins would redirect to the front end by default.
1919
- Fixed a bug where SSO users were able to “reset” their passwords.
2020
- Fixed JavaScript error that occurred if there was problem sending a password-reset email.
21+
- Fixed an error that could occur when working with an entry whose type is no longer allowed by its section/field. ([#16539](https://github.com/craftcms/cms/issues/16539))
2122

2223
## 5.6.1 - 2025-01-22
2324

src/elements/Entry.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1530,7 +1530,12 @@ public function getType(): EntryType
15301530
fn(EntryType $entryType) => $entryType->id === $this->_typeId,
15311531
);
15321532
if (!$entryType) {
1533-
throw new InvalidConfigException("Invalid entry type ID: $this->_typeId");
1533+
// Maybe the section/field no longer allows this type,
1534+
// so get it directly from the Entries service instead
1535+
$entryType = Craft::$app->getEntries()->getEntryTypeById($this->_typeId);
1536+
if (!$entryType) {
1537+
throw new InvalidConfigException("Invalid entry type ID: $this->_typeId");
1538+
}
15341539
}
15351540
} else {
15361541
// Default to the section/field's first entry type

0 commit comments

Comments
 (0)