You are here

public function LingotekManagementRelatedEntitiesForm::calculateNestedEntities in Lingotek Translation 3.4.x

Same name and namespace in other branches
  1. 8.2 src/Form/LingotekManagementRelatedEntitiesForm.php \Drupal\lingotek\Form\LingotekManagementRelatedEntitiesForm::calculateNestedEntities()
  2. 4.0.x src/Form/LingotekManagementRelatedEntitiesForm.php \Drupal\lingotek\Form\LingotekManagementRelatedEntitiesForm::calculateNestedEntities()
  3. 3.0.x src/Form/LingotekManagementRelatedEntitiesForm.php \Drupal\lingotek\Form\LingotekManagementRelatedEntitiesForm::calculateNestedEntities()
  4. 3.1.x src/Form/LingotekManagementRelatedEntitiesForm.php \Drupal\lingotek\Form\LingotekManagementRelatedEntitiesForm::calculateNestedEntities()
  5. 3.2.x src/Form/LingotekManagementRelatedEntitiesForm.php \Drupal\lingotek\Form\LingotekManagementRelatedEntitiesForm::calculateNestedEntities()
  6. 3.3.x src/Form/LingotekManagementRelatedEntitiesForm.php \Drupal\lingotek\Form\LingotekManagementRelatedEntitiesForm::calculateNestedEntities()
  7. 3.5.x src/Form/LingotekManagementRelatedEntitiesForm.php \Drupal\lingotek\Form\LingotekManagementRelatedEntitiesForm::calculateNestedEntities()
  8. 3.6.x src/Form/LingotekManagementRelatedEntitiesForm.php \Drupal\lingotek\Form\LingotekManagementRelatedEntitiesForm::calculateNestedEntities()
  9. 3.7.x src/Form/LingotekManagementRelatedEntitiesForm.php \Drupal\lingotek\Form\LingotekManagementRelatedEntitiesForm::calculateNestedEntities()
  10. 3.8.x src/Form/LingotekManagementRelatedEntitiesForm.php \Drupal\lingotek\Form\LingotekManagementRelatedEntitiesForm::calculateNestedEntities()

Deprecated

in lingotek:3.1.0 and is removed from lingotek:4.0.0.

See also

\Drupal\lingotek\RelatedEntities\RelatedEntitiesDetectorInterface

File

src/Form/LingotekManagementRelatedEntitiesForm.php, line 177

Class

LingotekManagementRelatedEntitiesForm
Form for bulk management of related content.

Namespace

Drupal\lingotek\Form

Code

public function calculateNestedEntities(ContentEntityInterface &$entity, &$visited = [], &$entities = []) {
  $visited[$entity
    ->bundle()][] = $entity
    ->id();
  $entities[$entity
    ->getEntityTypeId()][] = $entity;
  $field_definitions = $this->entityFieldManager
    ->getFieldDefinitions($entity
    ->getEntityTypeId(), $entity
    ->bundle());
  foreach ($field_definitions as $k => $definition) {
    $field_type = $field_definitions[$k]
      ->getType();
    if ($field_type === 'entity_reference' || $field_type === 'er_viewmode' || $field_type === 'entity_reference_revisions' || $field_type === 'cohesion_entity_reference_revisions') {
      $target_entity_type_id = $field_definitions[$k]
        ->getFieldStorageDefinition()
        ->getSetting('target_type');
      $target_entity_type = $this->entityTypeManager
        ->getDefinition($target_entity_type_id);
      if ($target_entity_type instanceof ContentEntityType) {
        foreach ($entity->{$k} as $field_item) {
          if (!isset($entities[$target_entity_type_id])) {
            $entities[$target_entity_type_id] = [];
          }
          $entities[$target_entity_type_id][] = $field_item->target_id;
        }
      }
    }
  }
  return $entities;
}