You are here

protected static function Minisite::getEntityPathAlias in Mini site 8

Get the path alias set on the parent entity.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The parent entity on which the field is set.

Return value

string Alias as a string or empty string if there is no alias.

1 call to Minisite::getEntityPathAlias()
Minisite::createInstance in src/Minisite.php
Create an instance of this class from the field items.

File

src/Minisite.php, line 366

Class

Minisite
Class Minisite.

Namespace

Drupal\minisite

Code

protected static function getEntityPathAlias(EntityInterface $entity) {

  // @todo: Add support for non-root entities (like paragraphs) to retrieve
  // alias information from.
  if ($entity
    ->hasField('path')) {
    $path_items = $entity->path
      ->get(0)
      ->getValue();
  }

  // Using toUrl() to get aliased entity URL.
  return !empty($path_items) && !empty($path_items['alias']) ? $entity
    ->toUrl()
    ->toString() : '';
}