You are here

public function ShareMessage::getUrl in Share Message 8

Gets the Share Message URL.

Parameters

array $context: The context for the token replacements.

Return value

string The URL for this Share Message.

Overrides ShareMessageInterface::getUrl

1 call to ShareMessage::getUrl()
ShareMessage::buildOGTags in src/Entity/ShareMessage.php
Returns Open Graph meta tags for <head>.

File

src/Entity/ShareMessage.php, line 477

Class

ShareMessage
Entity class for the Share Message entity.

Namespace

Drupal\sharemessage\Entity

Code

public function getUrl($context) {
  $options = [
    'absolute' => TRUE,
  ];
  if ($this->enforce_usage) {
    $options['query'] = [
      'smid' => $this->id,
    ];
  }
  $uri = $this
    ->getTokenizedField($this->share_url, $context, Url::fromRoute('<current>')
    ->getInternalPath());
  if (strpos($uri, '://') !== FALSE) {
    return Url::fromUri($uri, $options)
      ->toString();
  }
  elseif ($url = \Drupal::pathValidator()
    ->getUrlIfValid($uri)) {
    return $url
      ->setAbsolute()
      ->toString();
  }
  else {
    return Url::fromUri('internal:/' . $uri, $options)
      ->toString();
  }
}