Same name and namespace in other branches
- 8.9.x core/lib/Drupal/Core/Entity/EntityInterface.php \Drupal\Core\Entity\EntityInterface::toUrl()
- 9 core/lib/Drupal/Core/Entity/EntityInterface.php \Drupal\Core\Entity\EntityInterface::toUrl()
Gets the URL object for the entity.
The entity must have an id already. Content entities usually get their IDs by saving them.
URI templates might be set in the links array in an annotation, for example:
links = {
"canonical" = "/node/{node}",
"edit-form" = "/node/{node}/edit",
"version-history" = "/node/{node}/revisions"
}
or specified in a callback function set like:
uri_callback = "comment_uri",
If the path is not set in the links array, the uri_callback function is used for setting the path. If this does not exist and the link relationship type is canonical, the path is set using the default template: entity/entityType/id.
Parameters
string $rel: The link relationship type, for example: canonical or edit-form. If none is provided, canonical is assumed, or edit-form if no canonical link exists.
array $options: See \Drupal\Core\Routing\UrlGeneratorInterface::generateFromRoute() for the available options.
Return value
\Drupal\Core\Url The URL object.
Throws
\Drupal\Core\Entity\EntityMalformedException
\Drupal\Core\Entity\Exception\UndefinedLinkTemplateException
1 call to EntityInterface::toUrl()
- Comment::permalink in core/
modules/ comment/ src/ Entity/ Comment.php - Returns the permalink URL for this comment.
1 method overrides EntityInterface::toUrl()
- EntityBase::toUrl in core/
lib/ Drupal/ Core/ Entity/ EntityBase.php - Gets the URL object for the entity.
File
- core/
lib/ Drupal/ Core/ Entity/ EntityInterface.php, line 136
Class
- EntityInterface
- Defines a common interface for all entity objects.
Namespace
Drupal\Core\EntityCode
public function toUrl($rel = NULL, array $options = []);