Skip to content

Commit

Permalink
Merge pull request #14360 from craftcms/bugfix/14347-relations-and-de…
Browse files Browse the repository at this point in the history
…lete-for-site

delete relations if the element was deleted for a site
  • Loading branch information
brandonkelly authored Feb 13, 2024
2 parents a98e62d + 1ea6c83 commit e3bfd9b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- Fixed a bug where GraphQL schema edit pages could include empty category headings.
- Fixed a bug where asset slideouts weren’t showing validation errors on the Filename field. ([#14329](https://github.com/craftcms/cms/issues/14329))
- Fixed a bug where element slideouts would open when long-pressing on an element’s “Remove” button within an element select input.
- Fixed a bug where relations weren’t getting deleted when an element was deleted for a site. ([#14347](https://github.com/craftcms/cms/issues/14347))

## 4.7.2.1 - 2024-02-08

Expand Down
16 changes: 16 additions & 0 deletions src/fields/BaseRelationField.php
Original file line number Diff line number Diff line change
Expand Up @@ -1013,6 +1013,22 @@ public function afterElementSave(ElementInterface $element, bool $isNew): void
parent::afterElementSave($element, $isNew);
}

/**
* @inheritdoc
*/
public function afterElementDeleteForSite(ElementInterface $element): void
{
if ($this->localizeRelations) {
Db::delete(DbTable::RELATIONS, [
'fieldId' => $this->id,
'sourceSiteId' => $element->siteId,
'sourceId' => $element->id,
]);
}

parent::afterElementDeleteForSite($element);
}

/**
* Normalizes the available sources into select input options.
*
Expand Down

0 comments on commit e3bfd9b

Please sign in to comment.