You are here

function _minisite_get_entity_from_path in Mini site 8

Get entity from provided path.

Parameters

string $path: Source path to find the entity.

Return value

\Drupal\Core\Entity\FieldableEntityInterface|null Found entity or NULL if the entity was not found.

1 call to _minisite_get_entity_from_path()
minisite_path_insert in ./minisite.module
Implements hook_path_insert().

File

./minisite.module, line 225
Main functions of the Minisite module.

Code

function _minisite_get_entity_from_path($path) {
  try {
    $params = Url::fromUri('internal:' . $path)
      ->getRouteParameters();
  } catch (\InvalidArgumentException $exception) {
    return NULL;
  }
  $entity_type = key($params);
  try {
    $storage = \Drupal::entityTypeManager()
      ->getStorage($entity_type);
  } catch (PluginNotFoundException $exception) {
    return NULL;
  }
  return $storage
    ->load($params[$entity_type]);
}