You are here

abstract class ExcludeContentFieldBase in Acquia Content Hub 8.2

Class ExcludeContentFieldBase.

Base class to exclude content field from being added to the serialized output.

@package Drupal\acquia_contenthub\EventSubscriber\ExcludeContentField

Hierarchy

  • class \Drupal\acquia_contenthub\EventSubscriber\ExcludeContentField\ExcludeContentFieldBase implements \Symfony\Component\EventDispatcher\EventSubscriberInterface

Expanded class hierarchy of ExcludeContentFieldBase

File

src/EventSubscriber/ExcludeContentField/ExcludeContentFieldBase.php, line 17

Namespace

Drupal\acquia_contenthub\EventSubscriber\ExcludeContentField
View source
abstract class ExcludeContentFieldBase implements EventSubscriberInterface {

  /**
   * Priority of the subscriber.
   *
   * @var int
   */
  public static $priority = 0;

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() {
    $events[AcquiaContentHubEvents::EXCLUDE_CONTENT_ENTITY_FIELD][] = [
      'excludeContentField',
      self::$priority,
    ];
    return $events;
  }

  /**
   * Prevent entity fields from being added to the serialized output.
   *
   * @param \Drupal\acquia_contenthub\Event\ExcludeEntityFieldEvent $event
   *   The content entity field serialization event.
   */
  public abstract function shouldExclude(ExcludeEntityFieldEvent $event) : bool;

  /**
   * Sets the "exclude" flag.
   *
   * @param \Drupal\acquia_contenthub\Event\ExcludeEntityFieldEvent $event
   *   The content entity field serialization event.
   */
  public function excludeContentField(ExcludeEntityFieldEvent $event) {
    if ($this
      ->shouldExclude($event)) {
      $event
        ->exclude();
      $event
        ->stopPropagation();
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ExcludeContentFieldBase::$priority public static property Priority of the subscriber. 5
ExcludeContentFieldBase::excludeContentField public function Sets the "exclude" flag.
ExcludeContentFieldBase::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to.
ExcludeContentFieldBase::shouldExclude abstract public function Prevent entity fields from being added to the serialized output. 5