diff --git a/CHANGELOG.md b/CHANGELOG.md index 816070a85..1d9149719 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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() diff --git a/system/src/Grav/Framework/Flex/FlexObject.php b/system/src/Grav/Framework/Flex/FlexObject.php index 43f0265b6..9b33fa67c 100644 --- a/system/src/Grav/Framework/Flex/FlexObject.php +++ b/system/src/Grav/Framework/Flex/FlexObject.php @@ -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')) {