You are here

private function ImportEntityManager::getParentEntity in Acquia Content Hub 8

Returns the parent entity.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity to get the parent from.

Return value

mixed The parent entity.

Throws

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException

\Drupal\Component\Plugin\Exception\PluginNotFoundException

\Drupal\Core\Entity\EntityMalformedException

1 call to ImportEntityManager::getParentEntity()
ImportEntityManager::findRootAncestorImportEntity in src/ImportEntityManager.php
Returns the entity's root ancestor's imported entity.

File

src/ImportEntityManager.php, line 945

Class

ImportEntityManager
Provides a service for managing imported entities' actions.

Namespace

Drupal\acquia_contenthub

Code

private function getParentEntity(EntityInterface $entity) {
  if ($entity
    ->getEntityTypeId() == 'path_alias') {
    $route_params = Url::fromUserInput($entity
      ->getPath())
      ->getRouteParameters();
    foreach ($route_params as $entity_type_id => $entity_id) {
      if (!\Drupal::entityTypeManager()
        ->hasDefinition($entity_type_id)) {

        // Skip in case of unknown entity type.
        continue;
      }
      $entity_from_route = \Drupal::entityTypeManager()
        ->getStorage($entity_type_id)
        ->load($entity_id);
      if ($entity
        ->getPath() !== "/{$entity_from_route->toUrl()->getInternalPath()}") {

        // Skip mismatched entities.
        continue;
      }
      return $entity_from_route;
    }
  }
  return $entity
    ->getParentEntity();
}