<?php
namespace App\Essesolutions\AdminBundle\EventListener\DataObject;
use App\Essesolutions\AdminBundle\Service\CopyReferencedValuesServiceInterface;
use Pimcore\Event\DataObjectEvents;
use Pimcore\Event\Model\DataObjectEvent;
use Pimcore\Model\DataObject\Concrete;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class DataHookListener implements EventSubscriberInterface
{
private CopyReferencedValuesServiceInterface $copyReferencedValuesService;
/**
* @param CopyReferencedValuesServiceInterface $copyReferencedValuesService
*/
public function __construct(
CopyReferencedValuesServiceInterface $copyReferencedValuesService
)
{
$this->copyReferencedValuesService = $copyReferencedValuesService;
}
/** {@inheritDoc} */
public static function getSubscribedEvents()
{
return [
DataObjectEvents::POST_UPDATE => 'onDataObjectSave'
];
}
/**
* @param DataObjectEvent $dataObjectEvent
*
* @return void
*/
public function onDataObjectSave(DataObjectEvent $dataObjectEvent)
{
if (!$dataObjectEvent->getObject() instanceof Concrete) {
return;
}
$this->copyReferencedValuesService->exec($dataObjectEvent->getObject());
}
}