You are here

public function PathMapping::getPath in Gatsby Live Preview & Incremental Builds 8

Same name and namespace in other branches
  1. 2.0.x src/PathMapping.php \Drupal\gatsby\PathMapping::getPath()

Gets the Gatsby path for a content-entity.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity to get the Gatsby path for.

Return value

string The Gatsby path for the entity.

Overrides PathMappingInterface::getPath

File

src/PathMapping.php, line 78

Class

PathMapping
Defines a class for mapping paths between Drupal and Gatsby.

Namespace

Drupal\gatsby

Code

public function getPath(EntityInterface $entity) : string {
  $alias = $this->pathAliasManager
    ->getAliasByPath('/node/' . $entity
    ->id());

  // If this is the front-page we don't want to pass the alias
  // (as Gatsby will likely 404).
  if ($alias === \Drupal::config('system.site')
    ->get('page.front')) {
    $alias = '';
  }

  // Check if there are any path mappings to be considered for this alias.
  $path_mapping = $this
    ->getPathMapping();
  if (!empty($path_mapping[$alias])) {
    $alias = $path_mapping[$alias];
  }
  return $alias;
}