<?php
namespace App\EventListener;
use App\Model\DataObject\Address;
use Pimcore\Event\Model\ElementEventInterface;
use Pimcore\Event\Model\DataObjectEvent;
//use Pimcore\Model\DataObject\Books;
use Pimcore\Model\DataObject;
use App\Twig\Extension\Apik;
class ObjectListener
{
public function onPreUpdate(ElementEventInterface $e)
{
if ($e instanceof DataObjectEvent) {
$obj = $e->getObject();
if($obj instanceof DataObject\News){
$obj->setSlug(Apik::toUrl($obj->getTitre()));
}
}
}
public function onPostAdd(ElementEventInterface $e)
{
if ($e instanceof DataObjectEvent) {
$obj = $e->getObject();
if($obj instanceof DataObject\News){
$obj->setSlug(Apik::toUrl($obj->getTitre()));
}
$obj->save();
}
}
}