You are here

public function TextItemField::onUnserializeContentField in Acquia Content Hub 8.2

Extract the stored filter_format uuid and retrieve the entity id.

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/TextItemField.php, line 40

Class

TextItemField
Manual handling for text item fields filter references.

Namespace

Drupal\acquia_contenthub\EventSubscriber\UnserializeContentField

Code

public function onUnserializeContentField(UnserializeCdfEntityFieldEvent $event) {
  if (!in_array($event
    ->getFieldMetadata()['type'], $this->fieldTypes)) {
    return;
  }
  $field = $event
    ->getField();
  $values = [];

  // Return early if no attr values are set.
  if (empty($field['value'])) {
    return;
  }
  foreach ($field['value'] as $langcode => $value) {
    foreach ($value as $delta => &$item) {
      if (!$item['format']) {
        continue;
      }
      $filter = $this
        ->getEntity($item['format'], $event);
      $item['format'] = $filter
        ->id();
    }
    $values[$langcode][$event
      ->getFieldName()] = $value;
  }
  $event
    ->setValue($values);
  $event
    ->stopPropagation();
}