public function ConfigPages::toUrl in Config Pages 8.3
Same name and namespace in other branches
- 8.2 src/Entity/ConfigPages.php \Drupal\config_pages\Entity\ConfigPages::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.
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
Overrides EntityBase::toUrl
File
- src/
Entity/ ConfigPages.php, line 210
Class
- ConfigPages
- Defines the config page entity class.
Namespace
Drupal\config_pages\EntityCode
public function toUrl($rel = 'canonical', array $options = []) {
$config_pages_type = ConfigPagesType::load($this
->bundle());
$menu = $config_pages_type
->get('menu');
$path = isset($menu['path']) ? $menu['path'] : '';
return $path ? Url::fromRoute('config_pages.' . $this
->bundle(), [
'config_pages' => $this
->id(),
], $options) : Url::fromRoute('entity.config_pages.canonical', [
'config_pages' => $this
->id(),
], $options);
}