vendor/elements/json-ld-reloaded-bundle/src/EventSubscriber/TemplateSubscriber.php line 26

Open in your IDE?
  1. <?php
  2. namespace Elements\Bundle\JsonLdReloadedBundle\EventSubscriber;
  3. use Elements\Bundle\JsonLdReloadedBundle\Event\JsonLdEvents;
  4. use Elements\Bundle\JsonLdReloadedBundle\Event\TemplateEvent;
  5. use Elements\Bundle\JsonLdReloadedBundle\Model\DataObject\JsonLdTemplate;
  6. use Pimcore\Model\Asset;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. class TemplateSubscriber implements EventSubscriberInterface
  9. {
  10.     public static function getSubscribedEvents()
  11.     {
  12.         return [
  13.             JsonLdEvents::TEMPLATE_NOT_FOUND => [
  14.                 ['resolveTemplate'1]
  15.             ]
  16.         ];
  17.     }
  18.     /**
  19.      * @param TemplateEvent $event
  20.      * @todo: creating a new "fake" JsonLdTemplate is ugly. There should be something like a StaticJsonTemplate where the template is supplied with the bundle in a separate folder.
  21.      */
  22.     public function resolveTemplate(TemplateEvent $event)
  23.     {
  24.         if ($event->getObject() instanceof Asset) {
  25.             $template = new JsonLdTemplate();
  26.             $template->setName('ImageObject');
  27.             $template->setItemType('imageObject');
  28.             $event->setTemplate($template);
  29.         }
  30.     }
  31. }