You are here

public function LoginDestination::viewDestination in Login Destination 8

Same name and namespace in other branches
  1. 8.2 src/Entity/LoginDestination.php \Drupal\login_destination\Entity\LoginDestination::viewDestination()

Prepare redirect destination for displaying.

Return value

string Destination path.

Overrides LoginDestinationInterface::viewDestination

File

src/Entity/LoginDestination.php, line 275

Class

LoginDestination
Defines a login destination configuration entity.

Namespace

Drupal\login_destination\Entity

Code

public function viewDestination() {
  if ($this
    ->isDestinationCurrent()) {
    $scheme = 'internal';
  }
  else {
    $url = Url::fromUri($this->destination_path);
    $label = $this->destination_path;
    if ($url
      ->isExternal()) {
      return Html::escape($label);
    }
    $scheme = parse_url($this->destination_path, PHP_URL_SCHEME);
  }
  if ($scheme === 'internal') {
    return t('Internal destination');
  }
  if ($scheme === 'entity') {
    $params = $url
      ->getRouteParameters();
    $entity = \Drupal::entityTypeManager()
      ->getStorage('node')
      ->load(reset($params));
    return $entity
      ->get('title')->value;
  }
  return Html::escape($this->destination_path);
}