You are here

class EntityViewDisplaySerializer in Acquia Content Hub 8.2

Serializer for entity view displays.

Hierarchy

Expanded class hierarchy of EntityViewDisplaySerializer

1 string reference to 'EntityViewDisplaySerializer'
acquia_contenthub.services.yml in ./acquia_contenthub.services.yml
acquia_contenthub.services.yml
1 service uses EntityViewDisplaySerializer
entity_view_display.data.serializer in ./acquia_contenthub.services.yml
Drupal\acquia_contenthub\EventSubscriber\SerializeConfig\EntityViewDisplaySerializer

File

src/EventSubscriber/SerializeConfig/EntityViewDisplaySerializer.php, line 14

Namespace

Drupal\acquia_contenthub\EventSubscriber\SerializeConfig
View source
class EntityViewDisplaySerializer implements EventSubscriberInterface {
  use LayoutBuilderDataHandlerTrait;

  /**
   * EntityViewDisplaySerializer constructor.
   *
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
   *   The entity type manager.
   */
  public function __construct(EntityTypeManagerInterface $entityTypeManager) {
    $this->entityTypeManager = $entityTypeManager;
  }

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() {
    $events = [];
    $events[AcquiaContentHubEvents::SERIALIZE_CONFIG_ENTITY][] = [
      'onSerializeConfigEntity',
      100,
    ];
    return $events;
  }

  /**
   * Serializes layout_builder 3rd party settings data on entity_view_displays.
   *
   * @param \Drupal\acquia_contenthub\Event\ConfigDataEvent $event
   *   The config data event object.
   *
   * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
   * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
   */
  public function onSerializeConfigEntity(ConfigDataEvent $event) {

    /** @var \Drupal\Core\Entity\Entity\EntityViewDisplay $entity */
    $entity = $event
      ->getEntity();
    if ($entity
      ->getEntityTypeId() !== 'entity_view_display') {
      return;
    }
    $sections = $entity
      ->getThirdPartySetting('layout_builder', 'sections') ?? [];
    if ($sections) {
      $data = $event
        ->getData();
      $data[$entity
        ->language()
        ->getId()]['third_party_settings']['layout_builder']['sections'] = $this
        ->serializeSections(...$sections);
      $event
        ->setData($data);
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
EntityViewDisplaySerializer::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to.
EntityViewDisplaySerializer::onSerializeConfigEntity public function Serializes layout_builder 3rd party settings data on entity_view_displays.
EntityViewDisplaySerializer::__construct public function EntityViewDisplaySerializer constructor.
LayoutBuilderDataHandlerTrait::$entityTypeManager protected property The entity type manager. 2
LayoutBuilderDataHandlerTrait::getComponentConfiguration protected function Gets configuration for a Layout Builder component.
LayoutBuilderDataHandlerTrait::serializeComponents protected function Prepares component to be serialized.
LayoutBuilderDataHandlerTrait::serializeSections protected function Prepares Layout Builder sections to be serialized.
LayoutBuilderDataHandlerTrait::unserializeComponents protected function Prepares Layout Builder components to be unserialized.
LayoutBuilderDataHandlerTrait::unserializeSections protected function Prepares Layout Builder sections to be unserialized.