Added $object->getOriginal() to get flex objects data before it was modified with update()

This commit is contained in:
Matias Griese 2021-09-09 14:14:42 +03:00
parent 21db2e7d4a
commit 1350cf5675
2 changed files with 15 additions and 1 deletions

View File

@ -6,6 +6,7 @@
* Added `route` and `request` to `onPageNotFound` event
* Added file upload/remove support for `Flex Forms`
* Added support for `flex-required@: not exists` and `flex-required@: '!exists'` in blueprints
* Added `$object->getOriginal()` to get flex objects data before it was modified with `update()`
* Throwing exceptions from Twig templates fires `onDisplayErrorPage.[code]` event allowing better error pages
3. [](#bugfix)
* Fixed escaping in PageIndex::getLevelListing()

View File

@ -71,6 +71,8 @@ class FlexObject implements FlexObjectInterface, FlexAuthorizeInterface
/** @var array */
private $_meta;
/** @var array */
protected $_original;
/** @var array */
protected $_changes;
/** @var string */
protected $storage_key;
@ -441,6 +443,16 @@ class FlexObject implements FlexObjectInterface, FlexAuthorizeInterface
return 0;
}
/**
* Get original data before update
*
* @return array
*/
public function getOriginal(): array
{
return $this->_original ?? [];
}
/**
* Get any changes based on data sent to update
*
@ -654,7 +666,8 @@ class FlexObject implements FlexObjectInterface, FlexAuthorizeInterface
}
// Store the changes
$this->_changes = Utils::arrayDiffMultidimensional($this->getElements(), $elements);
$this->_original = $this->getElements();
$this->_changes = Utils::arrayDiffMultidimensional($this->_original, $elements);
}
if ($files && method_exists($this, 'setUpdatedMedia')) {