You are here

class DepCalcExcludeLingotekContentMetadataSubscriber in Lingotek Translation 3.6.x

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

Hierarchy

Expanded class hierarchy of DepCalcExcludeLingotekContentMetadataSubscriber

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

File

src/EventSubscriber/DepCalcExcludeLingotekContentMetadataSubscriber.php, line 9

Namespace

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

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

    // DependencyCalculatorEvents::FILTER_FIELDS from depcalc module.
    $events['depcalc_filter_fields'][] = [
      'onFilterFields',
      1002,
    ];
    return $events;
  }

  /**
   * Filter fields.
   *
   * @param \Drupal\depcalc\Event\FilterDependencyCalculationFieldsEvent $event
   *   Filter Dependency Calculation Fields.
   */
  public function onFilterFields(FilterDependencyCalculationFieldsEvent $event) {
    $fields = array_filter($event
      ->getFields(), function ($field) {
      return $this
        ->includeField($field);
    }, ARRAY_FILTER_USE_BOTH);
    $event
      ->setFields(...$fields);
  }

  /**
   * 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