public function ContentEntityCdfNormalizer::getMultilevelReferencedFields in Acquia Content Hub 8
Get multilevel entity reference fields.
Get the fields from a given entity and add them to the given content hub entity object. This also includes dependencies of the dependencies.
Parameters
\Drupal\Core\Entity\ContentEntityInterface $entity: The Drupal Entity.
array $referenced_entities: The list of Multilevel referenced entities. This must be passed as an initialized array.
array $context: Additional Context such as the account.
int $depth: The depth of the referenced entity (levels down from main entity).
Return value
\Drupal\Core\Entity\ContentEntityInterface[] All referenced entities.
1 call to ContentEntityCdfNormalizer::getMultilevelReferencedFields()
- ContentEntityCdfNormalizer::normalize in src/Normalizer/ ContentEntityCdfNormalizer.php 
- Normalizes an object into a set of arrays/scalars.
File
- src/Normalizer/ ContentEntityCdfNormalizer.php, line 831 
Class
- ContentEntityCdfNormalizer
- Converts the Drupal entity object to a Acquia Content Hub CDF array.
Namespace
Drupal\acquia_contenthub\NormalizerCode
public function getMultilevelReferencedFields(ContentEntityInterface $entity, array &$referenced_entities, array $context = [], $depth = 0) {
  $depth++;
  $maximum_depth = $this->config
    ->get('acquia_contenthub.entity_config')
    ->get('dependency_depth');
  $maximum_depth = is_int($maximum_depth) ? $maximum_depth : 3;
  // Collecting all referenced_entities UUIDs.
  $uuids = array_keys($referenced_entities);
  // Obtaining all the referenced entities for the current entity.
  $ref_entities = $this
    ->getReferencedFields($entity, $context);
  foreach ($ref_entities as $uuid => $entity) {
    if (!in_array($uuid, $uuids)) {
      // @todo This if-condition is a hack to avoid Vocabulary entities.
      if ($entity instanceof ContentEntityInterface) {
        $referenced_entities[$uuid] = $entity;
        // Only search for dependencies if we are below the maximum depth
        // configured by the admin. If not set, a default of 3 will be used.
        if ($depth < $maximum_depth) {
          $this
            ->getMultilevelReferencedFields($entity, $referenced_entities, $context, $depth);
        }
      }
    }
  }
  return $referenced_entities;
}