class SerializeCdfEntityFieldEvent in Acquia Content Hub 8.2
Event fired when serializing individual entity fields for syndication.
Subscribers to this event should manipulate $this->fieldData as necessary in order place values in the proper array format for the CDF serialization process. An empty $this->fieldData will prevent this key/value from being syndicated.
Hierarchy
- class \Drupal\acquia_contenthub\Event\SerializeCdfEntityFieldEvent extends \Symfony\Component\EventDispatcher\Event
Expanded class hierarchy of SerializeCdfEntityFieldEvent
See also
\Drupal\acquia_contenthub\AcquiaContentHubEvents
17 files declare their use of SerializeCdfEntityFieldEvent
- AcquiaContentHubSerializerTestBase.php in tests/
src/ Kernel/ AcquiaContentHubSerializerTestBase.php - ContentEntityHandler.php in src/
EventSubscriber/ Cdf/ ContentEntityHandler.php - ContentFieldMetadataTrait.php in src/
EventSubscriber/ SerializeContentField/ ContentFieldMetadataTrait.php - EntityMetatagsSerializer.php in modules/
acquia_contenthub_metatag/ src/ EventSubscriber/ SerializeContentField/ EntityMetatagsSerializer.php - EntityReferenceFieldSerializer.php in src/
EventSubscriber/ SerializeContentField/ EntityReferenceFieldSerializer.php
File
- src/
Event/ SerializeCdfEntityFieldEvent.php, line 20
Namespace
Drupal\acquia_contenthub\EventView source
class SerializeCdfEntityFieldEvent extends Event {
/**
* The entity being serialized.
*
* @var \Drupal\Core\Entity\ContentEntityInterface
*/
protected $entity;
/**
* The name of the field being serialized.
*
* @var string
*/
protected $fieldName;
/**
* The field being serialized.
*
* @var \Drupal\Core\Field\FieldItemListInterface
*/
protected $field;
/**
* The array of data to serialize for this field.
*
* @var array
*/
protected $fieldData;
/**
* The main return object of the serialization process.
*
* @var \Acquia\ContentHubClient\CDF\CDFObject
*/
protected $cdf;
/**
* SerializeCdfEntityFieldEvent constructor.
*
* @param \Drupal\Core\Entity\ContentEntityInterface $entity
* The entity to which the field belongs.
* @param string $field_name
* The name of the field.
* @param \Drupal\Core\Field\FieldItemListInterface $field
* The field item list object.
* @param \Acquia\ContentHubClient\CDF\CDFObject $cdf
* The CDF Object being created.
*/
public function __construct(ContentEntityInterface $entity, string $field_name, FieldItemListInterface $field, CDFObject $cdf) {
$this->entity = $entity;
$this->fieldName = $field_name;
$this->field = $field;
$this->cdf = $cdf;
}
/**
* The entity to which the field belongs.
*
* @return \Drupal\Core\Entity\ContentEntityInterface
* Entity.
*/
public function getEntity() {
return $this->entity;
}
/**
* The name of the field.
*
* @return string
* Field name.
*/
public function getFieldName() {
return $this->fieldName;
}
/**
* The field item list object.
*
* @return \Drupal\Core\Field\FieldItemListInterface
* Field item list object.
*/
public function getField() {
return $this->field;
}
/**
* The field item list object for a particular language.
*
* @param string $langcode
* The language of the field value to get.
*
* @return \Drupal\Core\Field\FieldItemListInterface
* Field item list object.
*/
public function getFieldTranslation($langcode) {
$entity = $this
->getEntity()
->getTranslation($langcode);
return $entity->{$this
->getField()
->getName()};
}
/**
* The field data to serialize.
*
* @return array
* Field data.
*/
public function getFieldData() {
return $this->fieldData;
}
/**
* Set the field data to serialize.
*
* @param array $data
* Field data.
*/
public function setFieldData(array $data) {
$this->fieldData = $data;
}
/**
* Returns the CDF Object.
*
* @return \Acquia\ContentHubClient\CDF\CDFObject
* CDF object.
*/
public function getCdf() {
return $this->cdf;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
SerializeCdfEntityFieldEvent:: |
protected | property | The main return object of the serialization process. | |
SerializeCdfEntityFieldEvent:: |
protected | property | The entity being serialized. | |
SerializeCdfEntityFieldEvent:: |
protected | property | The field being serialized. | |
SerializeCdfEntityFieldEvent:: |
protected | property | The array of data to serialize for this field. | |
SerializeCdfEntityFieldEvent:: |
protected | property | The name of the field being serialized. | |
SerializeCdfEntityFieldEvent:: |
public | function | Returns the CDF Object. | |
SerializeCdfEntityFieldEvent:: |
public | function | The entity to which the field belongs. | |
SerializeCdfEntityFieldEvent:: |
public | function | The field item list object. | |
SerializeCdfEntityFieldEvent:: |
public | function | The field data to serialize. | |
SerializeCdfEntityFieldEvent:: |
public | function | The name of the field. | |
SerializeCdfEntityFieldEvent:: |
public | function | The field item list object for a particular language. | |
SerializeCdfEntityFieldEvent:: |
public | function | Set the field data to serialize. | |
SerializeCdfEntityFieldEvent:: |
public | function | SerializeCdfEntityFieldEvent constructor. |