You are here

public function LayoutBuilderFieldUnserializer::onUnserializeContentField in Acquia Content Hub 8.2

Handling for Layout Builder sections.

Parameters

\Drupal\acquia_contenthub\Event\UnserializeCdfEntityFieldEvent $event: The unserialize event.

Throws

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException

\Drupal\Component\Plugin\Exception\PluginNotFoundException

File

src/EventSubscriber/UnserializeContentField/LayoutBuilderFieldUnserializer.php, line 59

Class

LayoutBuilderFieldUnserializer
Layout builder field unserializer fallback subscriber.

Namespace

Drupal\acquia_contenthub\EventSubscriber\UnserializeContentField

Code

public function onUnserializeContentField(UnserializeCdfEntityFieldEvent $event) {
  $event_field_type = $event
    ->getFieldMetadata()['type'];
  if ($event_field_type !== $this->fieldType) {
    return;
  }
  $field = $event
    ->getField();
  $values = [];
  if (!empty($field['value'])) {
    foreach ($field['value'] as $langcode => $sections) {
      foreach ($this
        ->unserializeSections($sections) as $section) {
        $values[$langcode][$event
          ->getFieldName()][] = [
          'section' => $section,
        ];
      }
    }
    $event
      ->setValue($values);
  }
  $event
    ->stopPropagation();
}