From cfa3ba70a0eb5794277a242ebc4396fae7f8b898 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Eahin?= Date: Thu, 27 Jul 2023 13:11:07 +0200 Subject: [PATCH] Improvement: Adds PRE_COPY event to the copy-contents-action (#14402) * improvement: adds PRE_COPY event to copy-contents-only action * improvement: adds PRE_COPY event to data-object and asset aswell for copy-content-only * fix: missing value assignment after event-dispatch --- models/Asset/Service.php | 7 +++++++ models/DataObject/Service.php | 7 +++++++ models/Document/Service.php | 7 +++++++ 3 files changed, 21 insertions(+) diff --git a/models/Asset/Service.php b/models/Asset/Service.php index 8a9907b5804..1b0bdd68171 100644 --- a/models/Asset/Service.php +++ b/models/Asset/Service.php @@ -185,6 +185,13 @@ public function copyContents(Asset $target, Asset $source): Asset throw new \Exception('Source and target have to be the same type'); } + // triggers actions before asset cloning + $event = new AssetEvent($source, [ + 'target_element' => $target, + ]); + \Pimcore::getEventDispatcher()->dispatch($event, AssetEvents::PRE_COPY); + $target = $event->getArgument('target_element'); + if (!$source instanceof Asset\Folder) { $target->setStream($source->getStream()); $target->setCustomSettings($source->getCustomSettings()); diff --git a/models/DataObject/Service.php b/models/DataObject/Service.php index cceb049de46..7f29d6b9d7d 100644 --- a/models/DataObject/Service.php +++ b/models/DataObject/Service.php @@ -245,6 +245,13 @@ public function copyContents(Concrete $target, Concrete $source): Concrete throw new \Exception('Source and target have to be the same type'); } + // triggers actions before object cloning + $event = new DataObjectEvent($source, [ + 'target_element' => $target, + ]); + \Pimcore::getEventDispatcher()->dispatch($event, DataObjectEvents::PRE_COPY); + $target = $event->getArgument('target_element'); + //load all in case of lazy loading fields self::loadAllObjectFields($source); diff --git a/models/Document/Service.php b/models/Document/Service.php index e7d2b7d45f0..03af090b946 100644 --- a/models/Document/Service.php +++ b/models/Document/Service.php @@ -226,6 +226,13 @@ public function copyContents(Document $target, Document $source): Link|Page|Docu throw new \Exception('Source and target have to be the same type'); } + // triggers actions before document cloning + $event = new DocumentEvent($source, [ + 'target_element' => $target, + ]); + \Pimcore::getEventDispatcher()->dispatch($event, DocumentEvents::PRE_COPY); + $target = $event->getArgument('target_element'); + if ($source instanceof Document\PageSnippet) { /** @var PageSnippet $target */ $target->setEditables($source->getEditables());