W3cubDocs

/Drupal 8

public function Entity::url

public Entity::url($rel = 'canonical', $options = array())

Gets the public URL for this entity.

Parameters

string $rel: The link relationship type, for example: canonical or edit-form.

array $options: See \Drupal\Core\Routing\UrlGeneratorInterface::generateFromRoute() for the available options.

Return value

string The URL for this entity.

Overrides EntityInterface::url

Deprecated

in Drupal 8.0.0, intended to be removed in Drupal 9.0.0 Please use toUrl() instead.

See also

\Drupal\Core\Entity\EntityInterface::toUrl

File

core/lib/Drupal/Core/Entity/Entity.php, line 278

Class

Entity
Defines a base entity class.

Namespace

Drupal\Core\Entity

Code

public function url($rel = 'canonical', $options = array()) {
  // While self::toUrl() will throw an exception if the entity has no id,
  // the expected result for a URL is always a string.
  if ($this->id() === NULL || !$this->hasLinkTemplate($rel)) {
    return '';
  }

  $uri = $this->toUrl($rel);
  $options += $uri->getOptions();
  $uri->setOptions($options);
  return $uri->toString();
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Entity!Entity.php/function/Entity::url/8.1.x