public function TextItemFieldSerializer::onSerializeContentField in Acquia Content Hub 8.2
Extract filter format UUID and place it into the serialized field values.
Parameters
\Drupal\acquia_contenthub\Event\SerializeCdfEntityFieldEvent $event: The content entity field serialization event.
File
- src/
EventSubscriber/ SerializeContentField/ TextItemFieldSerializer.php, line 62
Class
- TextItemFieldSerializer
- Subscribes to entity field serialization to extract the filter format uuid.
Namespace
Drupal\acquia_contenthub\EventSubscriber\SerializeContentFieldCode
public function onSerializeContentField(SerializeCdfEntityFieldEvent $event) {
if (!in_array($event
->getField()
->getFieldDefinition()
->getType(), $this->fieldTypes)) {
return;
}
$this
->setFieldMetaData($event);
$data = [];
$data['field_type'] = $event
->getField()
->getFieldDefinition()
->getType();
/** @var \Drupal\Core\Entity\TranslatableInterface $entity */
$entity = $event
->getEntity();
foreach ($entity
->getTranslationLanguages() as $langcode => $language) {
$field = $event
->getFieldTranslation($langcode);
foreach ($field as $item) {
$values = $item
->getValue();
if (!empty($values['format']) && ($format = $this->storage
->load($values['format']))) {
$values['format'] = $format
->uuid();
}
$data['value'][$langcode][] = $values;
}
}
$event
->setFieldData($data);
$event
->stopPropagation();
}