public function duplicate(TemplateDuplicateEvent $event, $eventName, EventDispatcherInterface $dispatcher)
    {
        if (null !== $source = TemplateQuery::create()->findPk($event->getSourceTemplateId())) {
            $source->setLocale($event->getLocale());
            
            $createEvent = new TemplateCreateEvent();
            $createEvent
                ->setLocale($event->getLocale())
                ->setTemplateName(
                    Translator::getInstance()->trans("Copy of %tpl", ["%tpl" => $source->getName() ])
                );
            
            $dispatcher->dispatch(TheliaEvents::TEMPLATE_CREATE, $createEvent);
            
            $clone = $createEvent->getTemplate();
            
            $attrList = AttributeTemplateQuery::create()->findByTemplateId($source->getId());
            
            /** @var  $feat AttributeTemplate */
            foreach ($attrList as $feat) {
                $dispatcher->dispatch(
                    TheliaEvents::TEMPLATE_ADD_ATTRIBUTE,
                    new TemplateAddAttributeEvent($clone, $feat->getAttributeId())
                );
            }
            
            $featList = FeatureTemplateQuery::create()->findByTemplateId($source->getId());
            
            /** @var  $feat FeatureTemplate */
            foreach ($featList as $feat) {
                $dispatcher->dispatch(
                    TheliaEvents::TEMPLATE_ADD_FEATURE,
                    new TemplateAddFeatureEvent($clone, $feat->getFeatureId())
                );
            }
            
            $event->setTemplate($clone);
        }
    }
public function duplicate(TemplateDuplicateEvent $event, $eventName, EventDispatcherInterface $dispatcher)
    {
        if (null !== $source = TemplateQuery::create()->findPk($event->getSourceTemplateId())) {
            $source->setLocale($event->getLocale());
            
            $createEvent = new TemplateCreateEvent();
            $createEvent
                ->setLocale($event->getLocale())
                ->setTemplateName(
                    Translator::getInstance()->trans("Copy of %tpl", ["%tpl" => $source->getName() ])
                );
            
            $dispatcher->dispatch(TheliaEvents::TEMPLATE_CREATE, $createEvent);
            
            $clone = $createEvent->getTemplate();
            
            $attrList = AttributeTemplateQuery::create()->findByTemplateId($source->getId());
            
            /** @var  $feat AttributeTemplate */
            foreach ($attrList as $feat) {
                $dispatcher->dispatch(
                    TheliaEvents::TEMPLATE_ADD_ATTRIBUTE,
                    new TemplateAddAttributeEvent($clone, $feat->getAttributeId())
                );
            }
            
            $featList = FeatureTemplateQuery::create()->findByTemplateId($source->getId());
            
            /** @var  $feat FeatureTemplate */
            foreach ($featList as $feat) {
                $dispatcher->dispatch(
                    TheliaEvents::TEMPLATE_ADD_FEATURE,
                    new TemplateAddFeatureEvent($clone, $feat->getFeatureId())
                );
            }
            
            $event->setTemplate($clone);
        }
    }
public function duplicate ( TemplateDuplicateEvent $ event , $ eventName , EventDispatcherInterface $ dispatcher ) { if ( null !== $ source = TemplateQuery :: create ( ) -> findPk ( $ event -> getSourceTemplateId ( ) ) ) { $ source -> setLocale ( $ event -> getLocale ( ) ) ; $ createEvent = new TemplateCreateEvent ( ) ; $ createEvent -> setLocale ( $ event -> getLocale ( ) ) -> setTemplateName ( Translator :: getInstance ( ) -> trans ( "Copy of %tpl" , [ "%tpl" => $ source -> getName ( ) ] ) ) ; $ dispatcher -> dispatch ( TheliaEvents :: TEMPLATE_CREATE , $ createEvent ) ; $ clone = $ createEvent -> getTemplate ( ) ; $ attrList = AttributeTemplateQuery :: create ( ) -> findByTemplateId ( $ source -> getId ( ) ) ; /** @var  $feat AttributeTemplate */ foreach ( $ attrList as $ feat ) { $ dispatcher -> dispatch ( TheliaEvents :: TEMPLATE_ADD_ATTRIBUTE , new TemplateAddAttributeEvent ( $ clone , $ feat -> getAttributeId ( ) ) ) ; } $ featList = FeatureTemplateQuery :: create ( ) -> findByTemplateId ( $ source -> getId ( ) ) ; /** @var  $feat FeatureTemplate */ foreach ( $ featList as $ feat ) { $ dispatcher -> dispatch ( TheliaEvents :: TEMPLATE_ADD_FEATURE , new TemplateAddFeatureEvent ( $ clone , $ feat -> getFeatureId ( ) ) ) ; } $ event -> setTemplate ( $ clone ) ; } }
Dupliucate an existing template entry

@param \Thelia\Core\Event\Template\TemplateCreateEvent $event
@param $eventName
@param EventDispatcherInterface $dispatcher
Dupliucate an existing template entry