You are here

protected function EntityMatcher::buildPath in Linkit 8.5

Same name and namespace in other branches
  1. 8.4 src/Plugin/Linkit/Matcher/EntityMatcher.php \Drupal\linkit\Plugin\Linkit\Matcher\EntityMatcher::buildPath()

Builds the path string used in the suggestion.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The matched entity.

Return value

string The path for this entity.

1 call to EntityMatcher::buildPath()
EntityMatcher::createSuggestion in src/Plugin/Linkit/Matcher/EntityMatcher.php
Creates a suggestion.
1 method overrides EntityMatcher::buildPath()
FileMatcher::buildPath in src/Plugin/Linkit/Matcher/FileMatcher.php
Builds the path string used in the suggestion.

File

src/Plugin/Linkit/Matcher/EntityMatcher.php, line 493

Class

EntityMatcher
Provides default linkit matchers for all entity types.

Namespace

Drupal\linkit\Plugin\Linkit\Matcher

Code

protected function buildPath(EntityInterface $entity) {
  $path = $entity
    ->toUrl('canonical', [
    'path_processing' => FALSE,
  ])
    ->toString();

  // For media entities, check if standalone URLs are allowed. If not, then
  // strip '/edit' from the end of the canonical URL returned
  // by $entity->toUrl().
  if ($entity
    ->getEntityTypeId() == 'media') {
    $standalone_url = \Drupal::config('media.settings')
      ->get('standalone_url');
    if (!$standalone_url) {

      // Strip "/edit".
      $path = substr($path, 0, -5);
    }
  }
  return $path;
}