public function FallbackFieldSerializer::onSerializeContentField in Acquia Content Hub 8.2
Directly reference the field's value property.
Parameters
\Drupal\acquia_contenthub\Event\SerializeCdfEntityFieldEvent $event: The content entity field serialization event.
3 calls to FallbackFieldSerializer::onSerializeContentField()
- EntityMetatagsSerializer::onSerializeContentField in modules/
acquia_contenthub_metatag/ src/ EventSubscriber/ SerializeContentField/ EntityMetatagsSerializer.php - Extract entity url to update metatag values.
- PasswordFieldSerializer::onSerializeContentField in src/
EventSubscriber/ SerializeContentField/ PasswordFieldSerializer.php - Manipulate the password properties.
- PathFieldSerializer::onSerializeContentField in src/
EventSubscriber/ SerializeContentField/ PathFieldSerializer.php - Manipulate the path properties.
3 methods override FallbackFieldSerializer::onSerializeContentField()
- EntityMetatagsSerializer::onSerializeContentField in modules/
acquia_contenthub_metatag/ src/ EventSubscriber/ SerializeContentField/ EntityMetatagsSerializer.php - Extract entity url to update metatag values.
- PasswordFieldSerializer::onSerializeContentField in src/
EventSubscriber/ SerializeContentField/ PasswordFieldSerializer.php - Manipulate the password properties.
- PathFieldSerializer::onSerializeContentField in src/
EventSubscriber/ SerializeContentField/ PathFieldSerializer.php - Manipulate the path properties.
File
- src/
EventSubscriber/ SerializeContentField/ FallbackFieldSerializer.php, line 31
Class
- FallbackFieldSerializer
- Subscribes to entity field serialization to handle basic field values.
Namespace
Drupal\acquia_contenthub\EventSubscriber\SerializeContentFieldCode
public function onSerializeContentField(SerializeCdfEntityFieldEvent $event) {
$this
->setFieldMetaData($event);
$data = [];
/** @var \Drupal\Core\Entity\TranslatableInterface $entity */
$entity = $event
->getEntity();
foreach ($entity
->getTranslationLanguages() as $langcode => $language) {
$field = $event
->getFieldTranslation($langcode);
// Set the translation value to represent null field data.
if (empty(count($field))) {
$data['value'][$langcode] = [];
continue;
}
foreach ($field as $item) {
if ($field
->getFieldDefinition()
->getFieldStorageDefinition()
->getCardinality() == FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED) {
$data['value'][$langcode][] = $item
->getValue();
}
else {
$data['value'][$langcode] = $item
->getValue();
}
}
}
$event
->setFieldData($data);
$event
->stopPropagation();
}