Skip to content

Commit

Permalink
Merge pull request #16168 from craftcms/bugfix/16156-apply-field-save…
Browse files Browse the repository at this point in the history
…-event-add-old-config

add outgoing field config to the ApplyFieldSaveEvent
  • Loading branch information
brandonkelly authored Nov 22, 2024
2 parents 1c36828 + a6cf6e7 commit e69fdf8
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Element indexes now sort by ID by default, for sources that don’t define a default sort option.
- Fixed a bug where element indexes were sorting by the first sortable attribute alphabetically by default, rather than the first sortable attribute defined by the element type.
- Fixed a bug where bulk asset actions where shown as available when subfolders were selected, when they shouldn’t have. ([#16151](https://github.com/craftcms/cms/issues/16151))
- Fixed a bug where `craft\events\ApplyFieldSaveEvent::$field` wasn’t being set consistently by `craft\services\Fields::EVENT_BEFORE_APPLY_FIELD_SAVE`. ([#16156](https://github.com/craftcms/cms/issues/16156))

## 4.13.2 - 2024-11-19

Expand Down
4 changes: 2 additions & 2 deletions src/events/ApplyFieldSaveEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
class ApplyFieldSaveEvent extends Event
{
/**
* @var FieldInterface|null The field associated with this event, if it already exists
* in the database or in memory.
* @var FieldInterface|null The field associated with this event, as
* configured before the changes are applied to it (if it already exists).
*/
public ?FieldInterface $field;

Expand Down
11 changes: 3 additions & 8 deletions src/services/Fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -1571,20 +1571,15 @@ public function applyFieldSave(string $fieldUid, array $data, string $context):
$groupRecord = $groupUid ? $this->_getGroupRecord($groupUid) : null;
$isNewField = $fieldRecord->getIsNewRecord();
$oldSettings = $fieldRecord->getOldAttribute('settings');
$oldField = !$isNewField ? $this->getFieldById($fieldRecord->id) : null;

// For control panel save requests, make sure we have all the custom data already saved on the object.
if (isset($this->_savingFields[$fieldUid])) {
$field = $this->_savingFields[$fieldUid];
} elseif (!$isNewField) {
$field = $this->getFieldById($fieldRecord->id);
} else {
$field = null;
}
$field = $this->_savingFields[$fieldUid] ?? $oldField;

// Fire a 'beforeApplyFieldSave' event
if ($this->hasEventHandlers(self::EVENT_BEFORE_APPLY_FIELD_SAVE)) {
$this->trigger(self::EVENT_BEFORE_APPLY_FIELD_SAVE, new ApplyFieldSaveEvent([
'field' => $field,
'field' => $oldField,
'config' => $data,
]));
}
Expand Down

0 comments on commit e69fdf8

Please sign in to comment.