Skip to content

Commit

Permalink
Fallback to getEntryTypeById()
Browse files Browse the repository at this point in the history
Fixes #16539
  • Loading branch information
brandonkelly committed Jan 27, 2025
1 parent 40029c6 commit 34c7f7e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- Fixed a bug where SSO logins would redirect to the front end by default.
- Fixed a bug where SSO users were able to “reset” their passwords.
- Fixed JavaScript error that occurred if there was problem sending a password-reset email.
- 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))

## 5.6.1 - 2025-01-22

Expand Down
7 changes: 6 additions & 1 deletion src/elements/Entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -1530,7 +1530,12 @@ public function getType(): EntryType
fn(EntryType $entryType) => $entryType->id === $this->_typeId,
);
if (!$entryType) {
throw new InvalidConfigException("Invalid entry type ID: $this->_typeId");
// Maybe the section/field no longer allows this type,
// so get it directly from the Entries service instead
$entryType = Craft::$app->getEntries()->getEntryTypeById($this->_typeId);
if (!$entryType) {
throw new InvalidConfigException("Invalid entry type ID: $this->_typeId");
}
}
} else {
// Default to the section/field's first entry type
Expand Down

0 comments on commit 34c7f7e

Please sign in to comment.