vendor/ibexa/fieldtype-page/src/lib/Event/Subscriber/AttributeSerializationSubscriber.php line 45

Open in your IDE?
  1. <?php
  2. /**
  3.  * @copyright Copyright (C) Ibexa AS. All rights reserved.
  4.  * @license For full copyright and license information view LICENSE file distributed with this source code.
  5.  */
  6. declare(strict_types=1);
  7. namespace Ibexa\FieldTypePage\Event\Subscriber;
  8. use Ibexa\FieldTypePage\Event\AttributeSerializationEvent;
  9. use Ibexa\FieldTypePage\Event\PageEvents;
  10. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  11. class AttributeSerializationSubscriber implements EventSubscriberInterface
  12. {
  13.     /**
  14.      * {@inheritdoc}
  15.      */
  16.     public static function getSubscribedEvents()
  17.     {
  18.         return [
  19.             PageEvents::ATTRIBUTE_SERIALIZATION => ['onAttributeSerialization'0],
  20.             PageEvents::ATTRIBUTE_DESERIALIZATION => ['onAttributeDeserialization'0],
  21.         ];
  22.     }
  23.     /**
  24.      * @param \Ibexa\FieldTypePage\Event\AttributeSerializationEvent $event
  25.      */
  26.     public function onAttributeSerialization(AttributeSerializationEvent $event): void
  27.     {
  28.         $deserializedValue $event->getDeserializedValue();
  29.         if ($deserializedValue === null || !is_scalar($deserializedValue)) {
  30.             return;
  31.         }
  32.         $event->setSerializedValue($deserializedValue);
  33.     }
  34.     /**
  35.      * @param \Ibexa\FieldTypePage\Event\AttributeSerializationEvent $event
  36.      */
  37.     public function onAttributeDeserialization(AttributeSerializationEvent $event): void
  38.     {
  39.         $serializedValue $event->getSerializedValue();
  40.         if ($serializedValue === null || !is_scalar($serializedValue)) {
  41.             return;
  42.         }
  43.         $event->setDeserializedValue($serializedValue);
  44.     }
  45. }
  46. class_alias(AttributeSerializationSubscriber::class, 'EzSystems\EzPlatformPageFieldType\Event\Subscriber\AttributeSerializationSubscriber');