You are here

class ExcludeEntityFieldEvent in Acquia Content Hub 8.2

Event fired when serializing individual entity fields for syndication.

Subscribers to this event will exclude entity fields for the CDF serialization process. $this->isExcludedField will prevent the key/value from being syndicated.

Hierarchy

Expanded class hierarchy of ExcludeEntityFieldEvent

See also

\Drupal\acquia_contenthub\AcquiaContentHubEvents

12 files declare their use of ExcludeEntityFieldEvent
ContentEntityHandler.php in src/EventSubscriber/Cdf/ContentEntityHandler.php
ExcludeContentFieldBase.php in src/EventSubscriber/ExcludeContentField/ExcludeContentFieldBase.php
RemoveIdField.php in src/EventSubscriber/ExcludeContentField/RemoveIdField.php
RemoveIdFieldTest.php in tests/src/Kernel/EventSubscriber/ExcludeContentField/RemoveIdFieldTest.php
RemoveLanguageField.php in src/EventSubscriber/ExcludeContentField/RemoveLanguageField.php

... See full list

File

src/Event/ExcludeEntityFieldEvent.php, line 18

Namespace

Drupal\acquia_contenthub\Event
View source
class ExcludeEntityFieldEvent extends Event {

  /**
   * The entity being serialized.
   *
   * @var \Drupal\Core\Entity\EntityInterface
   */
  protected $entity;

  /**
   * The name of the field being serialized.
   *
   * @var string
   */
  protected $fieldName;

  /**
   * The "exclude" flag.
   *
   * If set to TRUE, the field will not be added to the CDF object.
   *
   * @var bool
   */
  protected $isExcludedField = FALSE;

  /**
   * The field being serialized.
   *
   * @var \Drupal\Core\Field\FieldItemListInterface
   */
  protected $field;

  /**
   * SerializeCdfEntityFieldEvent constructor.
   *
   * @param \Drupal\Core\Entity\EntityInterface $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.
   */
  public function __construct(EntityInterface $entity, string $field_name, FieldItemListInterface $field) {
    $this->entity = $entity;
    $this->fieldName = $field_name;
    $this->field = $field;
  }

  /**
   * Get the entity being processed.
   *
   * @return \Drupal\Core\Entity\EntityInterface
   *   The entity being processed.
   */
  public function getEntity() : EntityInterface {
    return $this->entity;
  }

  /**
   * The field item list object.
   *
   * @return \Drupal\Core\Field\FieldItemListInterface
   *   Field item list object.
   */
  public function getField() : FieldItemListInterface {
    return $this->field;
  }

  /**
   * The name of the field.
   *
   * @return string
   *   Field name.
   */
  public function getFieldName() : string {
    return $this->fieldName;
  }

  /**
   * Sets the "exclude" flag.
   */
  public function exclude() {
    $this->isExcludedField = TRUE;
  }

  /**
   * Returns the "exclude" flag state.
   *
   * @return bool
   *   "Exclude" flag state.
   */
  public function isExcluded() : bool {
    return $this->isExcludedField;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ExcludeEntityFieldEvent::$entity protected property The entity being serialized.
ExcludeEntityFieldEvent::$field protected property The field being serialized.
ExcludeEntityFieldEvent::$fieldName protected property The name of the field being serialized.
ExcludeEntityFieldEvent::$isExcludedField protected property The "exclude" flag.
ExcludeEntityFieldEvent::exclude public function Sets the "exclude" flag.
ExcludeEntityFieldEvent::getEntity public function Get the entity being processed.
ExcludeEntityFieldEvent::getField public function The field item list object.
ExcludeEntityFieldEvent::getFieldName public function The name of the field.
ExcludeEntityFieldEvent::isExcluded public function Returns the "exclude" flag state.
ExcludeEntityFieldEvent::__construct public function SerializeCdfEntityFieldEvent constructor.