vendor/indabasolutions/webtoprintdownloadbundle/EventListener/UpdateTemplateListener.php line 75

Open in your IDE?
  1. <?php
  2. namespace IndabaSolutions\WebToPrintDownloadBundle\EventListener;
  3. use IndabaSolutions\WebToPrintDownloadBundle\Repository\DataObjectRepository;
  4. use IndabaSolutions\WebToPrintDownloadBundle\Service\TemplateProcessorService;
  5. use Pimcore\Event\Model\DataObjectEvent;
  6. /**
  7.  * UpdateTemplateListener
  8.  */
  9. class UpdateTemplateListener
  10. {
  11.     /**
  12.      * @var TemplateProcessorService $templateProcessorService
  13.      */
  14.     protected TemplateProcessorService $templateProcessorService;
  15.     
  16.     /**
  17.      * __construct
  18.      *
  19.      * @param  mixed $templateProcessorService
  20.      * @return void
  21.      */
  22.     public function __construct(TemplateProcessorService $templateProcessorService)
  23.     {
  24.         $this->templateProcessorService $templateProcessorService;
  25.     }
  26.     
  27.     /**
  28.      * setResult
  29.      *
  30.      * @param  DataObjectEvent $event
  31.      * @return void
  32.      */
  33.     protected function setResult(DataObjectEvent $event): void
  34.     {
  35.         $element $event->getElement();
  36.         $templateClass $this->templateProcessorService->getTemplateClass();
  37.         $componentClass $this->templateProcessorService->getComponentClass();
  38.         if ($element instanceof $templateClass) {
  39.             $html $this->templateProcessorService->renderTemplateObject($element);
  40.             $element->setResult($html);
  41.         }
  42.         if ($element instanceof $componentClass) {
  43.             $templateClass $templateClass;
  44.             try {
  45.                 $relatedTemplates DataObjectRepository::getRelatedFrom(
  46.                     $templateClass'components'$element->getId()
  47.                 );
  48.                 foreach ($relatedTemplates as $templateObject) {
  49.                     $templateObject->setResult(null);
  50.                 }
  51.             } catch (\Exception $e) {}
  52.         }
  53.     }
  54.     
  55.     /**
  56.      * onUpdateDo
  57.      *
  58.      * @param  DataObjectEvent $event
  59.      * @return void
  60.      */
  61.     protected function onUpdateDo(DataObjectEvent $event): void
  62.     {
  63.         $this->setResult($event);
  64.     }
  65.     
  66.     /**
  67.      * onObjectPreUpdate
  68.      *
  69.      * @param  DataObjectEvent $event
  70.      * @return void
  71.      */
  72.     public function onObjectPreUpdate(DataObjectEvent $event): void
  73.     {
  74.         $this->onUpdateDo($event);
  75.     }
  76. }