Skip to content

Commit

Permalink
Improvement: Adds PRE_COPY event to the copy-contents-action (pimcore…
Browse files Browse the repository at this point in the history
…#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
  • Loading branch information
SahinU88 authored Jul 27, 2023
1 parent ac7532b commit cfa3ba7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
7 changes: 7 additions & 0 deletions models/Asset/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
7 changes: 7 additions & 0 deletions models/DataObject/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
7 changes: 7 additions & 0 deletions models/Document/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit cfa3ba7

Please sign in to comment.