src/Event/SuluApiEventSubscriber.php line 31

Open in your IDE?
  1. <?php
  2. namespace App\Event;
  3. use App\Event\SuluApiEvent;
  4. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  5. use Sulu\Bundle\FormBundle\Entity\Dynamic;
  6. use Sulu\Bundle\FormBundle\Event\FormSavePostEvent;
  7. use Symfony\Contracts\HttpClient\HttpClientInterface;
  8. class SuluApiEventSubscriber implements EventSubscriberInterface
  9. {
  10.     private $id;
  11.     private $pwd;
  12.     private $client;
  13.     public function __construct(HttpClientInterface $client)
  14.     {
  15.         $this->id 'btenreiro';
  16.         $this->pwd 'ben';
  17.         $this->client $client;
  18.     }
  19.     public static function getSubscribedEvents(): array
  20.     {
  21.         return [
  22.             FormSavePostEvent::NAME => "suluApi"
  23.         ];
  24.     }
  25.     public function suluApi(FormSavePostEvent $event): void
  26.     {
  27.         $dynamic $event->getData();
  28.         if (!$dynamic instanceof Dynamic) {
  29.             return;
  30.         }
  31.         $form $dynamic->getForm()->serializeForLocale($dynamic->getLocale(), $dynamic);
  32.         if ($form && strpos($form['title'], "Hub") === 0) {
  33.             $apiCall = new SuluApiEvent($this->id$this->pwd$this->client);
  34.             $apiCall->sendDraft();
  35.         }
  36.     }
  37.     
  38. }