Skip to content

Commit

Permalink
Merge pull request #15125 from craftcms/bugfix/15123-deleting-global-…
Browse files Browse the repository at this point in the history
…sets

delete global set without layout
  • Loading branch information
brandonkelly authored Jun 3, 2024
2 parents 7d1df83 + b940547 commit ebbadb8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
- Fixed a bug where field conditions weren’t working reliably for nested entries within Matrix fields set to the inline-editable blocks view mode. ([#15104](https://github.com/craftcms/cms/issues/15104))
- Fixed a bug where the `serve` command could hang. ([#14977](https://github.com/craftcms/cms/issues/14977))
- Fixed a bug where nested entry edit pages would always redirect to the Entries index, even if they were nested under a different element type. ([#15101](https://github.com/craftcms/cms/issues/15101))
- Fixed an error that occurred when attempting to delete a global set without a field layout. ([#15123](https://github.com/craftcms/cms/issues/15123))

## 5.1.7 - 2024-05-25

Expand Down
12 changes: 7 additions & 5 deletions src/services/Globals.php
Original file line number Diff line number Diff line change
Expand Up @@ -506,13 +506,15 @@ public function handleDeletedGlobalSet(ConfigEvent $event): void
->where(['id' => $globalSetRecord->id])
->scalar();

$fieldLayout = Craft::$app->getFields()->getLayoutById($fieldLayoutId);

Craft::$app->getElements()->deleteElementById($globalSetRecord->id);

// Delete the field layout after the element has been deleted
if ($fieldLayout) {
Craft::$app->getFields()->deleteLayout($fieldLayout);
if ($fieldLayoutId) {
$fieldLayout = Craft::$app->getFields()->getLayoutById($fieldLayoutId);

// Delete the field layout after the element has been deleted
if ($fieldLayout) {
Craft::$app->getFields()->deleteLayout($fieldLayout);
}
}

$transaction->commit();
Expand Down

0 comments on commit ebbadb8

Please sign in to comment.