<?php
namespace Elements\Bundle\JsonLdReloadedBundle\EventSubscriber;
use Elements\Bundle\JsonLdReloadedBundle\Event\JsonLdEvents;
use Elements\Bundle\JsonLdReloadedBundle\Event\TemplateEvent;
use Elements\Bundle\JsonLdReloadedBundle\Model\DataObject\JsonLdTemplate;
use Pimcore\Model\Asset;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class TemplateSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents()
{
return [
JsonLdEvents::TEMPLATE_NOT_FOUND => [
['resolveTemplate', 1]
]
];
}
/**
* @param TemplateEvent $event
* @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.
*/
public function resolveTemplate(TemplateEvent $event)
{
if ($event->getObject() instanceof Asset) {
$template = new JsonLdTemplate();
$template->setName('ImageObject');
$template->setItemType('imageObject');
$event->setTemplate($template);
}
}
}