You are here

protected function EntityTraversal::getAllReverseRelationships in General Data Protection Regulation 8

Same name and namespace in other branches
  1. 8.2 modules/gdpr_fields/src/EntityTraversal.php \Drupal\gdpr_fields\EntityTraversal::getAllReverseRelationships()
  2. 3.0.x modules/gdpr_fields/src/EntityTraversal.php \Drupal\gdpr_fields\EntityTraversal::getAllReverseRelationships()

Gets all reverse relationships configured in the system.

Return value

array Information about reversible relationships.

1 call to EntityTraversal::getAllReverseRelationships()
EntityTraversal::doTraversalRecursive in modules/gdpr_fields/src/EntityTraversal.php
Traverses the entity relationship tree.

File

modules/gdpr_fields/src/EntityTraversal.php, line 252

Class

EntityTraversal
Base class for traversing entities.

Namespace

Drupal\gdpr_fields

Code

protected function getAllReverseRelationships() {
  if ($this->reverseRelationshipFields !== NULL) {

    // Make sure reverse relationships are cached.
    // as this is called many times in the recursion loop.
    return $this->reverseRelationshipFields;
  }
  $this->reverseRelationshipFields = [];

  /* @var \Drupal\gdpr_fields\Entity\GdprFieldConfigEntity $config  */
  foreach ($this->configStorage
    ->loadMultiple() as $config) {
    foreach ($config
      ->getAllFields() as $field) {
      if ($field->enabled && $field
        ->isOwner()) {
        foreach ($this->entityFieldManager
          ->getFieldDefinitions($config
          ->id(), $field->bundle) as $field_definition) {
          if ($field_definition
            ->getName() == $field->name && $field_definition
            ->getType() == 'entity_reference') {
            $this->reverseRelationshipFields[] = [
              'entity_type' => $config
                ->id(),
              'bundle' => $field->bundle,
              'field' => $field->name,
              'config' => $field,
              'target_type' => $field_definition
                ->getSetting('target_type'),
            ];
          }
        }
      }
    }
  }
  return $this->reverseRelationshipFields;
}