You are here

class AcquiaContentHubExcludeLingotekContentMetadataFromSerializationSubscriber in Lingotek Translation 3.7.x

Same name and namespace in other branches
  1. 4.0.x src/EventSubscriber/AcquiaContentHubExcludeLingotekContentMetadataFromSerializationSubscriber.php \Drupal\lingotek\EventSubscriber\AcquiaContentHubExcludeLingotekContentMetadataFromSerializationSubscriber
  2. 3.6.x src/EventSubscriber/AcquiaContentHubExcludeLingotekContentMetadataFromSerializationSubscriber.php \Drupal\lingotek\EventSubscriber\AcquiaContentHubExcludeLingotekContentMetadataFromSerializationSubscriber
  3. 3.8.x src/EventSubscriber/AcquiaContentHubExcludeLingotekContentMetadataFromSerializationSubscriber.php \Drupal\lingotek\EventSubscriber\AcquiaContentHubExcludeLingotekContentMetadataFromSerializationSubscriber

Hierarchy

Expanded class hierarchy of AcquiaContentHubExcludeLingotekContentMetadataFromSerializationSubscriber

1 string reference to 'AcquiaContentHubExcludeLingotekContentMetadataFromSerializationSubscriber'
lingotek.services.yml in ./lingotek.services.yml
lingotek.services.yml
1 service uses AcquiaContentHubExcludeLingotekContentMetadataFromSerializationSubscriber
lingotek.acquia_contenthub_exclude_content_metadata_subscriber in ./lingotek.services.yml
Drupal\lingotek\EventSubscriber\AcquiaContentHubExcludeLingotekContentMetadataFromSerializationSubscriber

File

src/EventSubscriber/AcquiaContentHubExcludeLingotekContentMetadataFromSerializationSubscriber.php, line 9

Namespace

Drupal\lingotek\EventSubscriber
View source
class AcquiaContentHubExcludeLingotekContentMetadataFromSerializationSubscriber implements EventSubscriberInterface {

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() {

    // AcquiaContentHubEvents::SERIALIZE_CONTENT_ENTITY_FIELD
    $events['serialize_content_entity_field'][] = [
      'onSerializeContentField',
      1001,
    ];
    return $events;
  }

  /**
   * Serialize content field event.
   *
   * @param \Drupal\acquia_contenthub\Event\SerializeCdfEntityFieldEvent $event
   *   Serialized CDF Entity Field event.
   */
  public function onSerializeContentField(SerializeCdfEntityFieldEvent $event) {
    $field = $event
      ->getField();
    if (!$this
      ->includeField($field)) {
      $event
        ->setExcluded();
      $event
        ->stopPropagation();
    }
  }

  /**
   * Whether we should include this field in the dependency calculation.
   *
   * @param \Drupal\Core\Field\FieldItemListInterface $field
   *   The entity field.
   *
   * @return bool
   *   TRUE if we should include the field, FALSE otherwise.
   */
  protected function includeField(FieldItemListInterface $field) {
    $definition = $field
      ->getFieldDefinition();
    if ($definition
      ->getType() === 'entity_reference' && $field
      ->getSetting('target_type') === 'lingotek_content_metadata') {
      return FALSE;
    }
    return TRUE;
  }

}

Members