src/EventSubscriber/Import/EntityMapper/VOD/Title/EmbeddedEntitySubscriber.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber\Import\EntityMapper\VOD\Title;
  3. use App\Application\EntityImportBundle\Event\EmbeddableMapperEvent;
  4. use App\Application\EntityImportBundle\ValueObject\ConfigItemPropertiesValue;
  5. use App\Entity\VOD\Title;
  6. use App\Entity\VOD\TitleLocalizedText;
  7. use App\Enum\VOD\SubtitleTypeEnum;
  8. use App\EventSubscriber\Import\EntityMapper\BaseEmbeddedSubscriber;
  9. /**
  10.  * Class EmbeddedEntitySubscriber.
  11.  */
  12. class EmbeddedEntitySubscriber extends BaseEmbeddedSubscriber
  13. {
  14.     public function onEntityPrePersist(EmbeddableMapperEvent $event): void
  15.     {
  16.         if (!$event->getEntity() instanceof Title) {
  17.             return;
  18.         }
  19.         $this->handleTitleLocalizedText($event->getEntity(), $event->getEmbeddedProperties(), $event->getData());
  20.     }
  21.     /**
  22.      * Responsible for providing data for required subtitles json field.
  23.      *
  24.      * @param \App\Entity\VOD\TitleLocalizedText $entity
  25.      *   The instance of the managed localized text entity
  26.      * @param \App\Application\EntityImportBundle\ValueObject\ConfigItemPropertiesValue $property
  27.      *   The property to map
  28.      * @param array $data
  29.      *   The parsed data of the current row
  30.      */
  31.     protected function handleRequiredSubtitles(
  32.         TitleLocalizedText $entity,
  33.         ConfigItemPropertiesValue $property,
  34.         array $data
  35.     ): void {
  36.         $value $this->getPropertyValue($property$data);
  37.         if ($this->getAllowedNullableCharacter() === $value) {
  38.             $this->setPropertyValue($entity$property, []);
  39.             return;
  40.         }
  41.         if (empty($value)) {
  42.             return;
  43.         }
  44.         $subtitleTypes = [];
  45.         foreach (array_map('trim'explode(','$value)) as $item) {
  46.             if (SubtitleTypeEnum::accepts($item)) {
  47.                 $subtitleTypes[] = $item;
  48.             }
  49.         }
  50.         $entity->setRequiredSubtitles($subtitleTypes);
  51.     }
  52. }