bundles/PfcPublicationBundle/EventListener/WorkflowListener.php line 26

Open in your IDE?
  1. <?php
  2. /**
  3.  * Created by PhpStorm.
  4.  * User: javra
  5.  * Date: 8/30/20
  6.  * Time: 5:21 PM
  7.  */
  8. namespace PfcPublicationBundle\EventListener;
  9. use App\Entity\Site;
  10. use Cocur\Slugify\Slugify;
  11. use Pimcore\Event\Model\DataObjectEvent;
  12. use Pimcore\Event\Model\ElementEventInterface;
  13. use Pimcore\Model\DataObject;
  14. use Pimcore\Model\Element\ValidationException;
  15. use Symfony\Component\Workflow\Registry;
  16. class WorkflowListener
  17. {
  18.     private $workflowRegistry;
  19.     /**
  20.      * @param ElementEventInterface $event
  21.      */
  22.     public function onPreUpdate(ElementEventInterface $event): void
  23.     {
  24.         if ($event instanceof DataObjectEvent) {
  25.             $objects $event->getObject();
  26. //            if ($objects->getClassName() == "Publication") {
  27.             $this->checkValidation($objects);
  28. //            }
  29.         }
  30.     }
  31.     /**
  32.      * @param $objects
  33.      * @throws ValidationException
  34.      */
  35.     public function checkValidation($objects): void
  36.     {
  37.         if ($objects instanceof DataObject\Publication) {
  38.             if (null == $objects->getPublicationName()) {
  39.                 $message 'Publication Name is required.';
  40.                 $result $message "<span style='color: red;'>*</span>" '<br>';
  41.                 throw new ValidationException($result403);
  42.             }
  43.             if ($objects->getPublicationName() != null) {
  44.                 $this->getPublicationData($objects);
  45.             }
  46.         }
  47.     }
  48.     /**
  49.      * @param $objects
  50.      */
  51.     public function getPublicationData($objects): void
  52.     {
  53.         $this->slugify = new Slugify();
  54.         $keyValue $this->slugify->slugify($objects->getPublicationName());
  55.         if ($keyValue != $objects->getKey()) {
  56.             $objects->setKey($keyValue);
  57.         }
  58.         $publicationObject DataObject::getByPath('/' $objects->getParent()->getFullPath());
  59.         $objects->setParentId($objects->getParentId());
  60.         $objects->setPath($publicationObject);
  61.     }
  62. }