Skip to content

Commit

Permalink
Throw an InvalidConfigException when entry is missing sectionId/field…
Browse files Browse the repository at this point in the history
…Id/ownerId

#15345
  • Loading branch information
brandonkelly committed Jul 15, 2024
1 parent 013fa50 commit 89e8e93
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Unreleased

- `craft\helpers\UrlHelper::actionUrl()` now returns URLs based on the primary site’s base URL (if it has one), for console requests if the `@web` alias wasn’t explicitly defined.
- An exception is now thrown when attempting to save an entry that’s missing `sectionId` or `fieldId` + `ownerId` values. ([#15345](https://github.com/craftcms/cms/discussions/15345))
- Fixed a bug where it wasn’t possible to expand/collapse descendants of disabled table rows within element select modals. ([#15337](https://github.com/craftcms/cms/issues/15337))
- Fixed a bug where addresses were getting truncated within address cards. ([#15338](https://github.com/craftcms/cms/issues/15338))

Expand Down
8 changes: 8 additions & 0 deletions src/elements/Entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,10 @@ public function getSupportedSites(): array
return $this->getField()->getSupportedSitesForElement($this);
}

if (!isset($this->sectionId)) {
throw new InvalidConfigException('Either `sectionId` or `fieldId` + `ownerId` must be set on the entry.');
}

$section = $this->getSection();
/** @var Site[] $allSites */
$allSites = ArrayHelper::index(Craft::$app->getSites()->getAllSites(true), 'id');
Expand Down Expand Up @@ -1027,6 +1031,10 @@ public function getUriFormat(): ?string
return $this->getField()->getUriFormatForElement($this);
}

if (!isset($this->sectionId)) {
throw new InvalidConfigException('Either `sectionId` or `fieldId` + `ownerId` must be set on the entry.');
}

$sectionSiteSettings = $this->getSection()->getSiteSettings();

if (!isset($sectionSiteSettings[$this->siteId])) {
Expand Down

0 comments on commit 89e8e93

Please sign in to comment.