You are here

public function EntityHelperTrait::entityCanonicalUrl in Facebook Instant Articles 3.x

Same name and namespace in other branches
  1. 8.2 src/Normalizer/EntityHelperTrait.php \Drupal\fb_instant_articles\Normalizer\EntityHelperTrait::entityCanonicalUrl()

Helper function to compute the canonical URL for a given entity.

Parameters

\Drupal\Core\Entity\ContentEntityInterface $entity: Content entity being normalized.

Return value

string The canonical URL for the given entity.

Throws

\Drupal\Core\Entity\EntityMalformedException

2 calls to EntityHelperTrait::entityCanonicalUrl()
InstantArticleContentEntityNormalizer::normalizeCanonicalUrl in src/Normalizer/InstantArticleContentEntityNormalizer.php
Normalize the canonical URL into the Instant Article object.
InstantArticleRssContentEntityNormalizer::normalize in src/Normalizer/InstantArticleRssContentEntityNormalizer.php

File

src/Normalizer/EntityHelperTrait.php, line 45

Class

EntityHelperTrait
Common entity data getters shared between the normalizers.

Namespace

Drupal\fb_instant_articles\Normalizer

Code

public function entityCanonicalUrl(ContentEntityInterface $entity) {
  if ($override = $this
    ->config()
    ->get('canonical_url_override')) {
    return $override . $entity
      ->toUrl('canonical')
      ->toString();
  }
  else {
    return $entity
      ->toUrl('canonical', [
      'absolute' => TRUE,
    ])
      ->toString();
  }
}