diff --git a/core/includes/menu.inc b/core/includes/menu.inc index bbf5c43..8086117 100644 --- a/core/includes/menu.inc +++ b/core/includes/menu.inc @@ -16,6 +16,7 @@ use Symfony\Cmf\Component\Routing\RouteObjectInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; +use Symfony\Component\Routing\Exception\ResourceNotFoundException; use Symfony\Component\Routing\Route; /** @@ -934,6 +935,9 @@ function menu_item_route_access(Route $route, $href, &$map, Request $request = N try { $request->attributes->add(\Drupal::service('router')->matchRequest($request)); } + catch (ResourceNotFoundException $e) { + return FALSE; + } catch (NotFoundHttpException $e) { return FALSE; } diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityListController.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityListController.php index 54afad2..f9033a4 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityListController.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityListController.php @@ -38,13 +38,13 @@ public function getOperations(EntityInterface $entity) { $operations['enable'] = array( 'title' => t('Enable'), 'weight' => -10, - ) + $entity->urlInfo('enable'); + ) + $entity->urlInfo('enable')->toArray(); } elseif ($entity->hasLinkTemplate('disable')) { $operations['disable'] = array( 'title' => t('Disable'), 'weight' => 40, - ) + $entity->urlInfo('disable'); + ) + $entity->urlInfo('disable')->toArray(); } } diff --git a/core/lib/Drupal/Core/Entity/Entity.php b/core/lib/Drupal/Core/Entity/Entity.php index 714aeeb..e77d87f 100644 --- a/core/lib/Drupal/Core/Entity/Entity.php +++ b/core/lib/Drupal/Core/Entity/Entity.php @@ -9,6 +9,7 @@ use Drupal\Core\Language\Language; use Drupal\Core\Session\AccountInterface; +use Drupal\Core\Url; /** * Defines a base entity class. @@ -37,13 +38,6 @@ protected $enforceIsNew; /** - * The URL generator. - * - * @var \Drupal\Core\Routing\UrlGeneratorInterface - */ - protected $urlGenerator; - - /** * Constructs an Entity object. * * @param array $values @@ -131,8 +125,7 @@ public function urlInfo($rel = 'canonical') { if (isset($link_templates[$rel])) { // If there is a template for the given relationship type, generate the path. - $uri['route_name'] = $link_templates[$rel]; - $uri['route_parameters'] = $this->urlRouteParameters($rel); + $uri = new Url($link_templates[$rel], $this->urlRouteParameters($rel)); } else { $bundle = $this->bundle(); @@ -153,14 +146,15 @@ public function urlInfo($rel = 'canonical') { $uri = $uri_callback($this); } else { - return array(); + return NULL; } } // Pass the entity data to url() so that alter functions do not need to // look up this entity again. - $uri['options']['entity_type'] = $this->getEntityTypeId(); - $uri['options']['entity'] = $this; + $uri + ->setOption('entity_type', $this->getEntityTypeId()) + ->setOption('entity', $this); return $uri; } @@ -170,7 +164,7 @@ public function urlInfo($rel = 'canonical') { */ public function getSystemPath($rel = 'canonical') { if ($uri = $this->urlInfo($rel)) { - return $this->urlGenerator()->getPathFromRoute($uri['route_name'], $uri['route_parameters']); + return $uri->getInternalPath(); } return ''; } @@ -199,12 +193,12 @@ protected function linkTemplates() { public function url($rel = 'canonical', $options = array()) { // While self::urlInfo() will throw an exception if the entity is new, // the expected result for a URL is always a string. - if ($this->isNew() || !$uri = $this->urlInfo($rel)) { + if ($this->isNew() || !$url = $this->urlInfo($rel)) { return ''; } - $options += $uri['options']; - return $this->urlGenerator()->generateFromRoute($uri['route_name'], $uri['route_parameters'], $options); + $url->setOptions($options + $url->getOptions()); + return $url->toString(); } /** @@ -381,17 +375,4 @@ protected function onSaveOrDelete() { } } - /** - * Wraps the URL generator. - * - * @return \Drupal\Core\Routing\UrlGeneratorInterface - * The URL generator. - */ - protected function urlGenerator() { - if (!$this->urlGenerator) { - $this->urlGenerator = \Drupal::urlGenerator(); - } - return $this->urlGenerator; - } - } diff --git a/core/lib/Drupal/Core/Entity/EntityInterface.php b/core/lib/Drupal/Core/Entity/EntityInterface.php index a91b694..933c34a 100644 --- a/core/lib/Drupal/Core/Entity/EntityInterface.php +++ b/core/lib/Drupal/Core/Entity/EntityInterface.php @@ -118,7 +118,7 @@ public function label(); * @param string $rel * The link relationship type, for example: canonical or edit-form. * - * @return + * @return \Drupal\Core\Url|null * An array containing the 'path' and 'options' keys used to build the URI * of the entity, and matching the signature of url(). */ diff --git a/core/lib/Drupal/Core/Entity/EntityListController.php b/core/lib/Drupal/Core/Entity/EntityListController.php index c56b229..1e926ed 100644 --- a/core/lib/Drupal/Core/Entity/EntityListController.php +++ b/core/lib/Drupal/Core/Entity/EntityListController.php @@ -98,13 +98,13 @@ public function getOperations(EntityInterface $entity) { $operations['edit'] = array( 'title' => $this->t('Edit'), 'weight' => 10, - ) + $entity->urlInfo('edit-form'); + ) + $entity->urlInfo('edit-form')->toArray(); } if ($entity->access('delete') && $entity->hasLinkTemplate('delete-form')) { $operations['delete'] = array( 'title' => $this->t('Delete'), 'weight' => 100, - ) + $entity->urlInfo('delete-form'); + ) + $entity->urlInfo('delete-form')->toArray(); } return $operations; diff --git a/core/lib/Drupal/Core/Form/ConfirmFormHelper.php b/core/lib/Drupal/Core/Form/ConfirmFormHelper.php index f2b4f25..f0e0e46 100644 --- a/core/lib/Drupal/Core/Form/ConfirmFormHelper.php +++ b/core/lib/Drupal/Core/Form/ConfirmFormHelper.php @@ -8,7 +8,8 @@ namespace Drupal\Core\Form; use Drupal\Component\Utility\String; -use Drupal\Component\Utility\Url; +use Drupal\Component\Utility\Url as UrlHelper; +use Drupal\Core\Url; use Symfony\Component\HttpFoundation\Request; /** @@ -36,7 +37,7 @@ public static function buildCancelLink(ConfirmFormInterface $form, Request $requ $query = $request->query; // If a destination is specified, that serves as the cancel link. if ($query->has('destination')) { - $options = Url::parse($query->get('destination')); + $options = UrlHelper::parse($query->get('destination')); $link = array( '#href' => $options['path'], '#options' => $options, @@ -44,19 +45,19 @@ public static function buildCancelLink(ConfirmFormInterface $form, Request $requ } // Check for a route-based cancel link. elseif ($route = $form->getCancelRoute()) { - if (empty($route['route_name'])) { - throw new \UnexpectedValueException(String::format('Missing route name in !class::getCancelRoute().', array('!class' => get_class($form)))); + if (!($route instanceof Url)) { + if (empty($route['route_name'])) { + throw new \UnexpectedValueException(String::format('Missing route name in !class::getCancelRoute().', array('!class' => get_class($form)))); + } + // Ensure there is something to pass as the params and options. + $route += array( + 'route_parameters' => array(), + 'options' => array(), + ); + $route = new Url($route['route_name'], $route['route_parameters'], $route['options']); } - // Ensure there is something to pass as the params and options. - $route += array( - 'route_parameters' => array(), - 'options' => array(), - ); - $link = array( - '#route_name' => $route['route_name'], - '#route_parameters' => $route['route_parameters'], - '#options' => $route['options'], - ); + + $link = $route->toRenderArray(); } $link['#type'] = 'link'; diff --git a/core/lib/Drupal/Core/Url.php b/core/lib/Drupal/Core/Url.php index 8535eee..3b1aad2 100644 --- a/core/lib/Drupal/Core/Url.php +++ b/core/lib/Drupal/Core/Url.php @@ -246,6 +246,23 @@ public function getOptions() { } /** + * Gets a specific option. + * + * @param string $name + * The name of the option. + * + * @return mixed + * The value for a specific option, or NULL if it does not exist. + */ + public function getOption($name) { + if (!isset($this->options[$name])) { + return NULL; + } + + return $this->options[$name]; + } + + /** * Sets the URL options. * * @param array $options @@ -312,6 +329,20 @@ public function toArray() { } /** + * Returns the route information for a render array. + * + * @return array + * An associative array suitable for a render array. + */ + public function toRenderArray() { + return array( + '#route_name' => $this->getRouteName(), + '#route_parameters' => $this->getRouteParameters(), + '#options' => $this->getOptions(), + ); + } + + /** * Returns the internal path for this route. * * This path will not include any prefixes, fragments, or query strings. diff --git a/core/lib/Drupal/Core/Utility/LinkGenerator.php b/core/lib/Drupal/Core/Utility/LinkGenerator.php index 5e8bf6d..43f638e 100644 --- a/core/lib/Drupal/Core/Utility/LinkGenerator.php +++ b/core/lib/Drupal/Core/Utility/LinkGenerator.php @@ -172,7 +172,7 @@ public function generateFromUrl($text, Url $url) { $url = String::checkPlain($url->toString()); // Sanitize the link text if necessary. - $text = $variables['options']['html'] ? $text : String::checkPlain($text); + $text = $variables['options']['html'] ? $variables['text'] : String::checkPlain($variables['text']); return '' . $text . ''; } diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockTypeFormController.php b/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockTypeFormController.php index 61408ed..d748e8d 100644 --- a/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockTypeFormController.php +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockTypeFormController.php @@ -91,8 +91,7 @@ public function save(array $form, array &$form_state) { $block_type = $this->entity; $status = $block_type->save(); - $uri = $block_type->urlInfo(); - $edit_link = \Drupal::l($this->t('Edit'), $uri['route_name'], $uri['route_parameters'], $uri['options']); + $edit_link = \Drupal::linkGenerator()->generateFromUrl($this->t('Edit'), $this->entity->urlInfo()); if ($status == SAVED_UPDATED) { drupal_set_message(t('Custom block type %label has been updated.', array('%label' => $block_type->label()))); watchdog('custom_block', 'Custom block type %label has been updated.', array('%label' => $block_type->label()), WATCHDOG_NOTICE, $edit_link); diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockTypeListController.php b/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockTypeListController.php index 84a8ad9..c01df04 100644 --- a/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockTypeListController.php +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockTypeListController.php @@ -41,8 +41,7 @@ public function buildHeader() { * Overrides \Drupal\Core\Entity\EntityListController::buildRow(). */ public function buildRow(EntityInterface $entity) { - $uri = $entity->urlInfo(); - $row['type'] = \Drupal::l($entity->label(), $uri['route_name'], $uri['route_parameters'], $uri['options']); + $row['type'] = \Drupal::linkGenerator()->generateFromUrl($entity->label(), $entity->urlInfo()); $row['description'] = filter_xss_admin($entity->description); return $row + parent::buildRow($entity); } diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index 25607de..ae645d1 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -15,6 +15,7 @@ use Drupal\Core\Entity\EntityChangedInterface; use Drupal\comment\CommentInterface; use Drupal\Core\Entity\Display\EntityViewDisplayInterface; +use Drupal\Core\Url; use Drupal\field\FieldInstanceInterface; use Drupal\field\FieldInterface; use Drupal\file\FileInterface; @@ -125,12 +126,12 @@ function comment_entity_bundle_info() { * Entity URI callback. */ function comment_uri(CommentInterface $comment) { - return array( - 'route_name' => 'comment.permalink', - 'route_parameters' => array( + return new Url( + 'comment.permalink', + array( 'comment' => $comment->id(), ), - 'options' => array('fragment' => 'comment-' . $comment->id()), + array('fragment' => 'comment-' . $comment->id()) ); } @@ -469,7 +470,7 @@ function comment_entity_view(EntityInterface $entity, EntityViewDisplayInterface 'attributes' => array('title' => t('Jump to the first comment of this posting.')), 'fragment' => 'comments', 'html' => TRUE, - ) + $entity->urlInfo(); + ) + $entity->urlInfo()->toArray(); if (\Drupal::moduleHandler()->moduleExists('history')) { $links['comment-new-comments'] = array( 'title' => '', @@ -503,7 +504,7 @@ function comment_entity_view(EntityInterface $entity, EntityViewDisplayInterface ); } else { - $links['comment-add'] += $entity->urlInfo(); + $links['comment-add'] += $entity->urlInfo()->toArray(); } } else { @@ -539,7 +540,7 @@ function comment_entity_view(EntityInterface $entity, EntityViewDisplayInterface ); } else { - $links['comment-add'] += $entity->urlInfo(); + $links['comment-add'] += $entity->urlInfo()->toArray(); } } } @@ -1416,18 +1417,19 @@ function template_preprocess_comment(&$variables) { $variables['permalink'] = l(t('Permalink'), ''); } else { - $uri = $comment->urlInfo(); - $uri['options'] += array('attributes' => array('class' => array('permalink'), 'rel' => 'bookmark')); - $variables['title'] = \Drupal::l($comment->subject->value, $uri['route_name'], $uri['route_parameters'], $uri['options']); + $url = $comment->urlInfo(); + $url->setOption('rel', 'bookmark'); + $url->setOption('attributes', array('class' => array('permalink'))); + $variables['title'] = \Drupal::linkGenerator()->generateFromUrl($comment->subject->value, $url); - $permalink_uri = $comment->permalink(); - $variables['permalink'] = \Drupal::l(t('Permalink'), $permalink_uri['route_name'], $permalink_uri['route_parameters'], $permalink_uri['options']); + $variables['permalink'] = \Drupal::linkGenerator()->generateFromUrl(t('Permalink'), $comment->permalink()); } $variables['submitted'] = t('Submitted by !username on !datetime', array('!username' => $variables['author'], '!datetime' => $variables['created'])); if ($comment->pid->target_id) { // Fetch and store the parent comment information for use in templates. + /** @var $comment_parent \Drupal\comment\CommentInterface */ $comment_parent = $comment->pid->entity; $account_parent = comment_prepare_author($comment_parent); $variables['parent_comment'] = $comment_parent; @@ -1446,9 +1448,10 @@ function template_preprocess_comment(&$variables) { $variables['parent_changed'] = format_date($comment_parent->changed->value); } $permalink_uri_parent = $comment_parent->permalink(); - $permalink_uri_parent['options'] += array('attributes' => array('class' => array('permalink'), 'rel' => 'bookmark')); - $variables['parent_title'] = \Drupal::l($comment_parent->subject->value, $permalink_uri_parent['route_name'], $permalink_uri_parent['route_parameters'], $permalink_uri_parent['options']); - $variables['parent_permalink'] = \Drupal::l(t('Parent permalink'), $permalink_uri_parent['route_name'], $permalink_uri_parent['route_parameters'], $permalink_uri_parent['options']); + $permalink_uri_parent->setOption('rel', 'bookmark'); + $permalink_uri_parent->setOption('attributes', array('class' => array('permalink'))); + $variables['parent_title'] = \Drupal::linkGenerator()->generateFromUrl($comment_parent->subject->value, $permalink_uri_parent); + $variables['parent_title'] = \Drupal::linkGenerator()->generateFromUrl(t('Parent permalink'), $permalink_uri_parent); $variables['parent'] = t('In reply to !parent_title by !parent_username', array('!parent_username' => $variables['parent_author'], '!parent_title' => $variables['parent_title'])); } diff --git a/core/modules/comment/lib/Drupal/comment/CommentBreadcrumbBuilder.php b/core/modules/comment/lib/Drupal/comment/CommentBreadcrumbBuilder.php index d0d39bb..0cf364d 100644 --- a/core/modules/comment/lib/Drupal/comment/CommentBreadcrumbBuilder.php +++ b/core/modules/comment/lib/Drupal/comment/CommentBreadcrumbBuilder.php @@ -53,8 +53,7 @@ public function build(array $attributes) { $entity = $this->entityManager ->getStorageController($attributes['entity_type']) ->load($attributes['entity_id']); - $uri = $entity->urlInfo(); - $breadcrumb[] = \Drupal::l($entity->label(), $uri['route_name'], $uri['route_parameters'], $uri['options']); + $breadcrumb[] = $this->linkGenerator()->generateFromUrl($entity->label(), $entity->urlInfo()); return $breadcrumb; } diff --git a/core/modules/comment/lib/Drupal/comment/CommentFormController.php b/core/modules/comment/lib/Drupal/comment/CommentFormController.php index cf1d724..8bfabae 100644 --- a/core/modules/comment/lib/Drupal/comment/CommentFormController.php +++ b/core/modules/comment/lib/Drupal/comment/CommentFormController.php @@ -399,7 +399,8 @@ public function save(array $form, array &$form_state) { $query['page'] = $page; } // Redirect to the newly posted comment. - $uri['options'] += array('query' => $query, 'fragment' => 'comment-' . $comment->id()); + $uri->setOption('query', $query); + $uri->setOption('fragment', 'comment-' . $comment->id()); } else { watchdog('content', 'Comment: unauthorized comment submitted or comment submitted to a closed post %subject.', array('%subject' => $comment->subject->value), WATCHDOG_WARNING); diff --git a/core/modules/comment/lib/Drupal/comment/CommentInterface.php b/core/modules/comment/lib/Drupal/comment/CommentInterface.php index 28ec9fb..abec437 100644 --- a/core/modules/comment/lib/Drupal/comment/CommentInterface.php +++ b/core/modules/comment/lib/Drupal/comment/CommentInterface.php @@ -28,10 +28,8 @@ /** * Returns the permalink URL for this comment. * - * @return array - * An array containing the 'path' and 'options' keys used to build the URI - * of the comment, and matching the signature of - * UrlGenerator::generateFromPath(). + * @return \Drupal\Core\Url + * A URL object for the permalink to this comment. */ public function permalink(); diff --git a/core/modules/comment/lib/Drupal/comment/CommentManagerInterface.php b/core/modules/comment/lib/Drupal/comment/CommentManagerInterface.php index 8226e23..7e2ffbe 100644 --- a/core/modules/comment/lib/Drupal/comment/CommentManagerInterface.php +++ b/core/modules/comment/lib/Drupal/comment/CommentManagerInterface.php @@ -19,8 +19,8 @@ * @param \Drupal\comment\CommentInterface $comment * The comment entity. * - * @return array - * An array returned by \Drupal\Core\Entity\EntityInterface::uri(). + * @return \Drupal\Core\Url + * A URL returned by \Drupal\Core\Entity\EntityInterface::urlInfo(). */ public function getParentEntityUri(CommentInterface $comment); diff --git a/core/modules/comment/lib/Drupal/comment/Controller/CommentController.php b/core/modules/comment/lib/Drupal/comment/Controller/CommentController.php index 73e8cfd..03798d7 100644 --- a/core/modules/comment/lib/Drupal/comment/Controller/CommentController.php +++ b/core/modules/comment/lib/Drupal/comment/Controller/CommentController.php @@ -91,9 +91,8 @@ public function commentApprove(CommentInterface $comment) { drupal_set_message($this->t('Comment approved.')); $permalink_uri = $comment->permalink(); - $permalink_uri['options']['absolute'] = TRUE; - $url = $this->urlGenerator()->generateFromRoute($permalink_uri['route_name'], $permalink_uri['route_parameters'], $permalink_uri['options']); - return new RedirectResponse($url); + $permalink_uri->setAbsolute(); + return new RedirectResponse($permalink_uri->toString()); } /** @@ -214,13 +213,13 @@ public function getReplyForm(Request $request, $entity_type, $entity_id, $field_ $account = $this->currentUser(); $uri = $entity->urlInfo(); - $path = $entity->getSystemPath(); + $uri->setAbsolute(); $build = array(); // Check if the user has the proper permissions. if (!$account->hasPermission('post comments')) { drupal_set_message($this->t('You are not authorized to post comments.'), 'error'); - return $this->redirect($uri['route_name'], $uri['route_parameters']); + return new RedirectResponse($uri->toString()); } // The user is not just previewing a comment. @@ -228,7 +227,7 @@ public function getReplyForm(Request $request, $entity_type, $entity_id, $field_ $status = $entity->{$field_name}->status; if ($status != COMMENT_OPEN) { drupal_set_message($this->t("This discussion is closed: you can't post new comments."), 'error'); - return $this->redirect($uri['route_name'], $uri['route_parameters']); + return new RedirectResponse($uri->toString()); } // $pid indicates that this is a reply to a comment. @@ -236,14 +235,14 @@ public function getReplyForm(Request $request, $entity_type, $entity_id, $field_ // Check if the user has the proper permissions. if (!$account->hasPermission('access comments')) { drupal_set_message($this->t('You are not authorized to view comments.'), 'error'); - return $this->redirect($uri['route_name'], $uri['route_parameters']); + return new RedirectResponse($uri->toString()); } // Load the parent comment. $comment = $this->entityManager()->getStorageController('comment')->load($pid); // Check if the parent comment is published and belongs to the entity. if (($comment->status->value == CommentInterface::NOT_PUBLISHED) || ($comment->entity_id->value != $entity->id())) { drupal_set_message($this->t('The comment you are replying to does not exist.'), 'error'); - return $this->redirect($uri['route_name'], $uri['route_parameters']); + return new RedirectResponse($uri->toString()); } // Display the parent comment. $build['comment_parent'] = $this->entityManager()->getViewBuilder('comment')->view($comment); diff --git a/core/modules/comment/lib/Drupal/comment/Entity/Comment.php b/core/modules/comment/lib/Drupal/comment/Entity/Comment.php index 9732c91..28ee19e 100644 --- a/core/modules/comment/lib/Drupal/comment/Entity/Comment.php +++ b/core/modules/comment/lib/Drupal/comment/Entity/Comment.php @@ -343,10 +343,9 @@ public static function postDelete(EntityStorageControllerInterface $storage_cont */ public function permalink() { $entity = entity_load($this->get('entity_type')->value, $this->get('entity_id')->value); - $uri = $entity->urlInfo(); - $uri['options'] = array('fragment' => 'comment-' . $this->id()); - - return $uri; + $url = $entity->urlInfo(); + $url->setOption('fragment', 'comment-' . $this->id()); + return $url; } /** diff --git a/core/modules/comment/lib/Drupal/comment/Form/CommentAdminOverview.php b/core/modules/comment/lib/Drupal/comment/Form/CommentAdminOverview.php index ebd2623..15af7ca 100644 --- a/core/modules/comment/lib/Drupal/comment/Form/CommentAdminOverview.php +++ b/core/modules/comment/lib/Drupal/comment/Form/CommentAdminOverview.php @@ -193,7 +193,6 @@ public function buildForm(array $form, array &$form_state, $type = 'new') { foreach ($comments as $comment) { /** @var $commented_entity \Drupal\comment\CommentInterface */ $commented_entity = $commented_entities[$comment->entity_type->value][$comment->entity_id->value]; - $commented_entity_uri = $commented_entity->urlInfo(); $username = array( '#theme' => 'username', '#account' => comment_prepare_author($comment), @@ -203,31 +202,22 @@ public function buildForm(array $form, array &$form_state, $type = 'new') { $body = $comment->comment_body->value; } $comment_permalink = $comment->permalink(); + $comment_permalink->setOption('attributes', array('title' => Unicode::truncate($body, 128))); $options[$comment->id()] = array( 'title' => array('data' => array('#title' => $comment->subject->value ?: $comment->id())), 'subject' => array( 'data' => array( '#type' => 'link', '#title' => $comment->subject->value, - '#route_name' => $comment_permalink['route_name'], - '#route_parameters' => $comment_permalink['route_parameters'], - '#options' => $comment_permalink['options'] + array( - 'attributes' => array( - 'title' => Unicode::truncate($body, 128), - ), - ), - ), + ) + $comment_permalink->toRenderArray(), ), 'author' => drupal_render($username), 'posted_in' => array( 'data' => array( '#type' => 'link', '#title' => $commented_entity->label(), - '#route_name' => $commented_entity_uri['route_name'], - '#route_parameters' => $commented_entity_uri['route_parameters'], - '#options' => $commented_entity_uri['options'], '#access' => $commented_entity->access('view'), - ), + ) + $commented_entity->urlInfo()->toRenderArray(), ), 'changed' => $this->date->format($comment->changed->value, 'short'), ); @@ -237,7 +227,7 @@ public function buildForm(array $form, array &$form_state, $type = 'new') { 'title' => $this->t('edit'), 'route_name' => 'comment.edit_page', 'route_parameters' => array('comment' => $comment->id()), - 'options' => $comment_uri['options'], + 'options' => $comment_uri->getOptions(), 'query' => $destination, ); if ($this->moduleHandler->invoke('content_translation', 'translate_access', array($comment))) { @@ -245,7 +235,7 @@ public function buildForm(array $form, array &$form_state, $type = 'new') { 'title' => $this->t('translate'), 'route_name' => 'content_translation.translation_overview_comment', 'route_parameters' => array('comment' => $comment->id()), - 'options' => $comment_uri['options'], + 'options' => $comment_uri->getOptions(), 'query' => $destination, ); } diff --git a/core/modules/comment/lib/Drupal/comment/Form/DeleteForm.php b/core/modules/comment/lib/Drupal/comment/Form/DeleteForm.php index f226305..3f5c59f 100644 --- a/core/modules/comment/lib/Drupal/comment/Form/DeleteForm.php +++ b/core/modules/comment/lib/Drupal/comment/Form/DeleteForm.php @@ -62,9 +62,7 @@ protected function actions(array $form, array &$form_state) { $actions = parent::actions($form, $form_state); // @todo Convert to getCancelRoute() after http://drupal.org/node/1987778. - $uri = $this->commentManager->getParentEntityUri($this->entity); - $actions['cancel']['#route_name'] = $uri['route_name']; - $actions['cancel']['#route_parameters'] = $uri['route_parameters']; + $actions['cancel'] = $this->commentManager->getParentEntityUri($this->entity)->toRenderArray(); return $actions; } diff --git a/core/modules/config/lib/Drupal/config/Tests/ConfigEntityListTest.php b/core/modules/config/lib/Drupal/config/Tests/ConfigEntityListTest.php index 682aeef..e8c064d 100644 --- a/core/modules/config/lib/Drupal/config/Tests/ConfigEntityListTest.php +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigEntityListTest.php @@ -54,15 +54,15 @@ function testList() { 'edit' => array ( 'title' => t('Edit'), 'weight' => 10, - ) + $entity->urlInfo(), + ) + $entity->urlInfo()->toArray(), 'disable' => array( 'title' => t('Disable'), 'weight' => 40, - ) + $entity->urlInfo('disable'), + ) + $entity->urlInfo('disable')->toArray(), 'delete' => array ( 'title' => t('Delete'), 'weight' => 100, - ) + $entity->urlInfo('delete-form'), + ) + $entity->urlInfo('delete-form')->toArray(), ); $actual_operations = $controller->getOperations($entity); @@ -126,11 +126,11 @@ function testList() { 'edit' => array( 'title' => t('Edit'), 'weight' => 10, - ) + $entity->urlInfo(), + ) + $entity->urlInfo()->toArray(), 'delete' => array( 'title' => t('Delete'), 'weight' => 100, - ) + $entity->urlInfo('delete-form'), + ) + $entity->urlInfo('delete-form')->toArray(), ); $actual_operations = $controller->getOperations($entity); diff --git a/core/modules/config_translation/config_translation.module b/core/modules/config_translation/config_translation.module index e3f1ac9..cd4e0a3 100644 --- a/core/modules/config_translation/config_translation.module +++ b/core/modules/config_translation/config_translation.module @@ -173,7 +173,7 @@ function config_translation_entity_operation_alter(array &$operations, EntityInt $operations['translate'] = array( 'title' => t('Translate'), 'href' => $entity->getSystemPath() . '/translate', - 'options' => $uri['options'], + 'options' => $uri->getOptions(), 'weight' => 50, ); } diff --git a/core/modules/contact/lib/Drupal/contact/CategoryFormController.php b/core/modules/contact/lib/Drupal/contact/CategoryFormController.php index 50b5203..58c7195 100644 --- a/core/modules/contact/lib/Drupal/contact/CategoryFormController.php +++ b/core/modules/contact/lib/Drupal/contact/CategoryFormController.php @@ -97,8 +97,7 @@ public function save(array $form, array &$form_state) { $category = $this->entity; $status = $category->save(); - $uri = $category->urlInfo(); - $edit_link = \Drupal::l($this->t('Edit'), $uri['route_name'], $uri['route_parameters'], $uri['options']); + $edit_link = \Drupal::linkGenerator()->generateFromUrl($this->t('Edit'), $this->entity->urlInfo()); if ($status == SAVED_UPDATED) { drupal_set_message(t('Category %label has been updated.', array('%label' => $category->label()))); diff --git a/core/modules/content_translation/content_translation.module b/core/modules/content_translation/content_translation.module index d981d39..7ff7509 100644 --- a/core/modules/content_translation/content_translation.module +++ b/core/modules/content_translation/content_translation.module @@ -177,7 +177,7 @@ function content_translation_entity_operation_alter(array &$operations, \Drupal\ if ($entity instanceof NodeInterface && $entity->isTranslatable()) { $operations['translate'] = array( 'title' => t('Translate'), - ) + $entity->urlInfo('drupal:content-translation-overview'); + ) + $entity->urlInfo('drupal:content-translation-overview')->toArray(); } } diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/Field/FieldFormatter/EntityReferenceLabelFormatter.php b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/Field/FieldFormatter/EntityReferenceLabelFormatter.php index ea13e17..ff92d43 100644 --- a/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/Field/FieldFormatter/EntityReferenceLabelFormatter.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/Field/FieldFormatter/EntityReferenceLabelFormatter.php @@ -68,10 +68,7 @@ public function viewElements(FieldItemListInterface $items) { $elements[$delta] = array( '#type' => 'link', '#title' => $label, - '#route_name' => $uri['route_name'], - '#route_parameters' => $uri['route_parameters'], - '#options' => $uri['options'], - ); + ) + $uri->toRenderArray(); } else { $elements[$delta] = array('#markup' => check_plain($label)); diff --git a/core/modules/field_ui/field_ui.module b/core/modules/field_ui/field_ui.module index bb8ec0b..78f58e7 100644 --- a/core/modules/field_ui/field_ui.module +++ b/core/modules/field_ui/field_ui.module @@ -197,19 +197,19 @@ function field_ui_entity_operation_alter(array &$operations, EntityInterface $en $operations['manage-fields'] = array( 'title' => t('Manage fields'), 'weight' => 15, - ) + $entity->urlInfo('field_ui-fields'); + ) + $entity->urlInfo('field_ui-fields')->toArray(); } if (user_access('administer '. $bundle_of . ' form display')) { $operations['manage-form-display'] = array( 'title' => t('Manage form display'), 'weight' => 20, - ) + $entity->urlInfo('field_ui-form-display'); + ) + $entity->urlInfo('field_ui-form-display')->toArray(); } if (user_access('administer '. $bundle_of . ' display')) { $operations['manage-display'] = array( 'title' => t('Manage display'), 'weight' => 25, - ) + $entity->urlInfo('field_ui-display'); + ) + $entity->urlInfo('field_ui-display')->toArray(); } } } diff --git a/core/modules/forum/forum.module b/core/modules/forum/forum.module index 2fb5036..10cb1e4 100644 --- a/core/modules/forum/forum.module +++ b/core/modules/forum/forum.module @@ -6,6 +6,7 @@ */ use Drupal\Core\Entity\EntityInterface; +use Drupal\Core\Url; use Drupal\field\Field; /** @@ -235,12 +236,9 @@ function forum_entity_bundle_info_alter(&$bundles) { * Entity URI callback used in forum_entity_bundle_info_alter(). */ function forum_uri($forum) { - return array( - 'route_name' => 'forum.page', - 'route_parameters' => array( - 'taxonomy_term' => $forum->id(), - ), - ); + return new Url('forum.page', array( + 'taxonomy_term' => $forum->id(), + )); } /** diff --git a/core/modules/image/lib/Drupal/image/ImageStyleListController.php b/core/modules/image/lib/Drupal/image/ImageStyleListController.php index 568b5be..15c940a 100644 --- a/core/modules/image/lib/Drupal/image/ImageStyleListController.php +++ b/core/modules/image/lib/Drupal/image/ImageStyleListController.php @@ -78,7 +78,7 @@ public function getOperations(EntityInterface $entity) { $flush = array( 'title' => t('Flush'), 'weight' => 200, - ) + $entity->urlInfo('flush-form'); + ) + $entity->urlInfo('flush-form')->toArray(); return parent::getOperations($entity) + array('flush' => $flush); } diff --git a/core/modules/image/lib/Drupal/image/Plugin/Field/FieldFormatter/ImageFormatter.php b/core/modules/image/lib/Drupal/image/Plugin/Field/FieldFormatter/ImageFormatter.php index 6a9a44e..c8af274 100644 --- a/core/modules/image/lib/Drupal/image/Plugin/Field/FieldFormatter/ImageFormatter.php +++ b/core/modules/image/lib/Drupal/image/Plugin/Field/FieldFormatter/ImageFormatter.php @@ -95,9 +95,9 @@ public function viewElements(FieldItemListInterface $items) { $image_link_setting = $this->getSetting('image_link'); // Check if the formatter involves a link. if ($image_link_setting == 'content') { - $uri = $items->getEntity()->urlInfo(); // @todo Remove when theme_image_formatter() has support for route name. $uri['path'] = $items->getEntity()->getSystemPath(); + $uri['options'] = $items->getEntity()->urlInfo()->getOptions(); } elseif ($image_link_setting == 'file') { $link_file = TRUE; diff --git a/core/modules/menu/lib/Drupal/menu/MenuFormController.php b/core/modules/menu/lib/Drupal/menu/MenuFormController.php index 9a7d93b..54c8123 100644 --- a/core/modules/menu/lib/Drupal/menu/MenuFormController.php +++ b/core/modules/menu/lib/Drupal/menu/MenuFormController.php @@ -205,8 +205,7 @@ public function save(array $form, array &$form_state) { $status = $menu->save(); - $uri = $menu->urlInfo(); - $edit_link = \Drupal::l($this->t('Edit'), $uri['route_name'], $uri['route_parameters'], $uri['options']); + $edit_link = \Drupal::linkGenerator()->generateFromUrl($this->t('Edit'), $this->entity->urlInfo()); if ($status == SAVED_UPDATED) { drupal_set_message(t('Menu %label has been updated.', array('%label' => $menu->label()))); watchdog('menu', 'Menu %label has been updated.', array('%label' => $menu->label()), WATCHDOG_NOTICE, $edit_link); diff --git a/core/modules/menu/lib/Drupal/menu/MenuListController.php b/core/modules/menu/lib/Drupal/menu/MenuListController.php index 18a3732..cae0b63 100644 --- a/core/modules/menu/lib/Drupal/menu/MenuListController.php +++ b/core/modules/menu/lib/Drupal/menu/MenuListController.php @@ -49,7 +49,7 @@ public function getOperations(EntityInterface $entity) { $operations['add'] = array( 'title' => t('Add link'), 'weight' => 20, - ) + $entity->urlInfo('add-form'); + ) + $entity->urlInfo('add-form')->toArray(); } if (isset($operations['delete'])) { $operations['delete']['title'] = t('Delete menu'); diff --git a/core/modules/menu_link/menu_link.module b/core/modules/menu_link/menu_link.module index dc86f4c..0f84af7 100644 --- a/core/modules/menu_link/menu_link.module +++ b/core/modules/menu_link/menu_link.module @@ -5,6 +5,7 @@ * Enables users to create menu links. */ +use Drupal\Core\Url; use Drupal\menu_link\Entity\MenuLink; use Drupal\menu_link\MenuLinkInterface; use Symfony\Cmf\Component\Routing\RouteObjectInterface; @@ -26,10 +27,7 @@ function menu_link_help($path, $arg) { * A menu link entity. */ function menu_link_uri(MenuLink $menu_link) { - return array( - 'route_name' => $menu_link->route_name, - 'route_parameters' => $menu_link->route_parameters, - ); + return new Url($menu_link->route_name, $menu_link->route_parameters); } /** diff --git a/core/modules/node/lib/Drupal/node/Controller/NodeController.php b/core/modules/node/lib/Drupal/node/Controller/NodeController.php index 4d62d12..f83e70b 100644 --- a/core/modules/node/lib/Drupal/node/Controller/NodeController.php +++ b/core/modules/node/lib/Drupal/node/Controller/NodeController.php @@ -129,7 +129,6 @@ public function page(NodeInterface $node) { $build = $this->buildPage($node); foreach ($node->uriRelationships() as $rel) { - $uri = $node->urlInfo($rel); // Set the node path as the canonical URL to prevent duplicate content. $build['#attached']['drupal_add_html_head_link'][] = array( array( diff --git a/core/modules/node/lib/Drupal/node/Form/NodeDeleteForm.php b/core/modules/node/lib/Drupal/node/Form/NodeDeleteForm.php index 93148d4..7517b33 100644 --- a/core/modules/node/lib/Drupal/node/Form/NodeDeleteForm.php +++ b/core/modules/node/lib/Drupal/node/Form/NodeDeleteForm.php @@ -62,9 +62,7 @@ protected function actions(array $form, array &$form_state) { $actions = parent::actions($form, $form_state); // @todo Convert to getCancelRoute() after http://drupal.org/node/1987778. - $uri = $this->entity->urlInfo(); - $actions['cancel']['#route_name'] = $uri['route_name']; - $actions['cancel']['#route_parameters'] = $uri['route_parameters']; + $actions['cancel'] = $this->entity->urlInfo()->toRenderArray(); return $actions; } diff --git a/core/modules/node/lib/Drupal/node/NodeListController.php b/core/modules/node/lib/Drupal/node/NodeListController.php index c4d01ce..3657e38 100644 --- a/core/modules/node/lib/Drupal/node/NodeListController.php +++ b/core/modules/node/lib/Drupal/node/NodeListController.php @@ -96,14 +96,14 @@ public function buildRow(EntityInterface $entity) { ); $langcode = $entity->language()->id; $uri = $entity->urlInfo(); + if ($langcode != Language::LANGCODE_NOT_SPECIFIED && isset($languages[$langcode])) { + $uri->setOption('language', $languages[$langcode]); + } $row['title']['data'] = array( '#type' => 'link', '#title' => $entity->label(), - '#route_name' => $uri['route_name'], - '#route_parameters' => $uri['route_parameters'], - '#options' => $uri['options'] + ($langcode != Language::LANGCODE_NOT_SPECIFIED && isset($languages[$langcode]) ? array('language' => $languages[$langcode]) : array()), '#suffix' => ' ' . drupal_render($mark), - ); + ) + $uri->toRenderArray(); $row['type'] = String::checkPlain(node_get_type_label($entity)); $row['author']['data'] = array( '#theme' => 'username', diff --git a/core/modules/node/node.module b/core/modules/node/node.module index bf79da6..fd2a3b0 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -10,6 +10,7 @@ use Drupal\Component\Utility\String; use Drupal\Core\Language\Language; +use Drupal\Core\Url; use Symfony\Component\HttpFoundation\Response; use Drupal\Core\Cache\Cache; use Drupal\Core\Database\Query\AlterableInterface; @@ -224,12 +225,9 @@ function node_entity_form_display_alter(EntityFormDisplayInterface $form_display * An array with 'path' as the key and the path to the node as its value. */ function node_uri(EntityInterface $node) { - return array( - 'route_name' => 'node.view', - 'route_parameters' => array( - 'node' => $node->id(), - ), - ); + return new Url('node.view', array( + 'node' => $node->id(), + )); } /** diff --git a/core/modules/picture/lib/Drupal/picture/PictureMappingListController.php b/core/modules/picture/lib/Drupal/picture/PictureMappingListController.php index e391676..bbcfc99 100644 --- a/core/modules/picture/lib/Drupal/picture/PictureMappingListController.php +++ b/core/modules/picture/lib/Drupal/picture/PictureMappingListController.php @@ -41,7 +41,7 @@ public function getOperations(EntityInterface $entity) { $operations['duplicate'] = array( 'title' => t('Duplicate'), 'weight' => 15, - ) + $entity->urlInfo('duplicate-form'); + ) + $entity->urlInfo('duplicate-form')->toArray(); return $operations; } diff --git a/core/modules/picture/lib/Drupal/picture/Plugin/Field/FieldFormatter/PictureFormatter.php b/core/modules/picture/lib/Drupal/picture/Plugin/Field/FieldFormatter/PictureFormatter.php index eb1864d..8cd1f49 100644 --- a/core/modules/picture/lib/Drupal/picture/Plugin/Field/FieldFormatter/PictureFormatter.php +++ b/core/modules/picture/lib/Drupal/picture/Plugin/Field/FieldFormatter/PictureFormatter.php @@ -116,9 +116,9 @@ public function viewElements(FieldItemListInterface $items) { $elements = array(); // Check if the formatter involves a link. if ($this->getSetting('image_link') == 'content') { - $uri = $items->getEntity()->urlInfo(); // @todo Remove when theme_picture_formatter() has support for route name. $uri['path'] = $items->getEntity()->getSystemPath(); + $uri['options'] = $items->getEntity()->urlInfo()->getOptions(); } elseif ($this->getSetting('image_link') == 'file') { $link_file = TRUE; diff --git a/core/modules/rdf/rdf.module b/core/modules/rdf/rdf.module index 057af3e..9fa110c 100644 --- a/core/modules/rdf/rdf.module +++ b/core/modules/rdf/rdf.module @@ -335,7 +335,6 @@ function rdf_preprocess_node(&$variables) { function rdf_preprocess_user(&$variables) { /** @var $account \Drupal\user\UserInterface */ $account = $variables['elements']['#user']; - $uri = $account->urlInfo(); $mapping = rdf_get_mapping('user', 'user'); $bundle_mapping = $mapping->getPreparedBundleMapping(); @@ -347,7 +346,7 @@ function rdf_preprocess_user(&$variables) { } // If we are on the user account page, add the relationship between the // sioc:UserAccount and the foaf:Person who holds the account. - if (\Drupal::request()->attributes->get(RouteObjectInterface::ROUTE_NAME) == $uri['route_name']) { + if (\Drupal::request()->attributes->get(RouteObjectInterface::ROUTE_NAME) == $account->urlInfo()->getRouteName()) { // Adds the markup for username as language neutral literal, see // rdf_preprocess_username(). $name_mapping = $mapping->getPreparedFieldMapping('name'); diff --git a/core/modules/shortcut/lib/Drupal/shortcut/ShortcutSetListController.php b/core/modules/shortcut/lib/Drupal/shortcut/ShortcutSetListController.php index 6741ed2..6c4bf1d 100644 --- a/core/modules/shortcut/lib/Drupal/shortcut/ShortcutSetListController.php +++ b/core/modules/shortcut/lib/Drupal/shortcut/ShortcutSetListController.php @@ -35,7 +35,7 @@ public function getOperations(EntityInterface $entity) { $operations['list'] = array( 'title' => t('List links'), - ) + $entity->urlInfo('customize-form'); + ) + $entity->urlInfo('customize-form')->toArray(); return $operations; } diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Form/OverviewTerms.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Form/OverviewTerms.php index 8e5bcce..9e4d010 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Form/OverviewTerms.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Form/OverviewTerms.php @@ -200,7 +200,6 @@ public function buildForm(array $form, array &$form_state, VocabularyInterface $ ); foreach ($current_page as $key => $term) { /** @var $term \Drupal\Core\Entity\EntityInterface */ - $uri = $term->urlInfo(); $form['terms'][$key]['#term'] = $term; $indentation = array(); if (isset($term->depth) && $term->depth > 0) { @@ -213,9 +212,7 @@ public function buildForm(array $form, array &$form_state, VocabularyInterface $ '#prefix' => !empty($indentation) ? drupal_render($indentation) : '', '#type' => 'link', '#title' => $term->label(), - '#route_name' => $uri['route_name'], - '#route_parameters' => $uri['route_parameters'], - ); + ) + $term->urlInfo()->toRenderArray(); if ($taxonomy_vocabulary->hierarchy != TAXONOMY_HIERARCHY_MULTIPLE && count($tree) > 1) { $parent_fields = TRUE; $form['terms'][$key]['term']['tid'] = array( @@ -258,17 +255,17 @@ public function buildForm(array $form, array &$form_state, VocabularyInterface $ 'edit' => array( 'title' => $this->t('edit'), 'query' => $destination, - ) + $term->urlInfo('edit-form'), + ) + $term->urlInfo('edit-form')->toArray(), 'delete' => array( 'title' => $this->t('delete'), 'query' => $destination, - ) + $term->urlInfo('delete-form'), + ) + $term->urlInfo('delete-form')->toArray(), ); if ($this->moduleHandler->moduleExists('content_translation') && content_translation_translate_access($term)) { $operations['translate'] = array( 'title' => $this->t('translate'), 'query' => $destination, - ) + $term->urlInfo('drupal:content-translation-overview'); + ) + $term->urlInfo('drupal:content-translation-overview')->toArray(); } $form['terms'][$key]['operations'] = array( '#type' => 'operations', diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/Field/FieldFormatter/LinkFormatter.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/Field/FieldFormatter/LinkFormatter.php index f7d0325..247427a 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/Field/FieldFormatter/LinkFormatter.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/Field/FieldFormatter/LinkFormatter.php @@ -39,14 +39,10 @@ public function viewElements(FieldItemListInterface $items) { else { /** @var $term \Drupal\taxonomy\TermInterface */ $term = $item->entity; - $uri = $term->urlInfo(); $elements[$delta] = array( '#type' => 'link', '#title' => $term->label(), - '#route_name' => $uri['route_name'], - '#route_parameters' => $uri['route_parameters'], - '#options' => $uri['options'], - ); + ) + $term->urlInfo()->toRenderArray(); if (!empty($item->_attributes)) { $elements[$delta]['#options'] += array('attributes' => array()); diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyFormController.php b/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyFormController.php index 6a02f1e..bc3e225 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyFormController.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyFormController.php @@ -130,8 +130,7 @@ public function save(array $form, array &$form_state) { $vocabulary->name = trim($vocabulary->name); $status = $vocabulary->save(); - $uri = $vocabulary->urlInfo(); - $edit_link = \Drupal::l($this->t('edit'), $uri['route_name'], $uri['route_parameters'], $uri['options']); + $edit_link = \Drupal::linkGenerator()->generateFromUrl($this->t('edit'), $this->entity->urlInfo()); switch ($status) { case SAVED_NEW: drupal_set_message($this->t('Created new vocabulary %name.', array('%name' => $vocabulary->name))); diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyListController.php b/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyListController.php index 104b360..2b1e86e 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyListController.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyListController.php @@ -40,11 +40,11 @@ public function getOperations(EntityInterface $entity) { $operations['list'] = array( 'title' => t('list terms'), 'weight' => 0, - ) + $entity->urlInfo('overview-form'); + ) + $entity->urlInfo('overview-form')->toArray(); $operations['add'] = array( 'title' => t('add terms'), 'weight' => 10, - ) + $entity->urlInfo('add-form'); + ) + $entity->urlInfo('add-form')->toArray(); unset($operations['delete']); return $operations; diff --git a/core/modules/taxonomy/taxonomy.module b/core/modules/taxonomy/taxonomy.module index bc7b30b..98be12d 100644 --- a/core/modules/taxonomy/taxonomy.module +++ b/core/modules/taxonomy/taxonomy.module @@ -7,6 +7,7 @@ use Drupal\Core\Entity\FieldableDatabaseStorageController; use Drupal\Core\Entity\EntityInterface; +use Drupal\Core\Url; use Drupal\file\FileInterface; use Drupal\node\Entity\Node; use Drupal\taxonomy\Entity\Term; @@ -124,12 +125,9 @@ function taxonomy_entity_bundle_info() { * Entity URI callback. */ function taxonomy_term_uri($term) { - return array( - 'route_name' => 'taxonomy.term_page', - 'route_parameters' => array( - 'taxonomy_term' => $term->id(), - ), - ); + return new Url('taxonomy.term_page', array( + 'taxonomy_term' => $term->id(), + )); } /** diff --git a/core/modules/user/lib/Drupal/user/Form/UserCancelForm.php b/core/modules/user/lib/Drupal/user/Form/UserCancelForm.php index 5d14e09..1176f01 100644 --- a/core/modules/user/lib/Drupal/user/Form/UserCancelForm.php +++ b/core/modules/user/lib/Drupal/user/Form/UserCancelForm.php @@ -144,9 +144,7 @@ public function buildForm(array $form, array &$form_state) { $form = parent::buildForm($form, $form_state); // @todo Convert to getCancelRoute() after https://drupal.org/node/1987896. - $uri = $this->entity->urlInfo(); - $form['actions']['cancel']['#route_name'] = $uri['route_name']; - $form['actions']['cancel']['#route_parameters'] = $uri['route_parameters']; + $form['actions']['cancel'] = $this->entity->urlInfo()->toRenderArray(); return $form; } diff --git a/core/modules/user/lib/Drupal/user/RoleFormController.php b/core/modules/user/lib/Drupal/user/RoleFormController.php index 0cf8cd4..873214f 100644 --- a/core/modules/user/lib/Drupal/user/RoleFormController.php +++ b/core/modules/user/lib/Drupal/user/RoleFormController.php @@ -68,8 +68,7 @@ public function save(array $form, array &$form_state) { $entity->set('label', trim($entity->label())); $status = $entity->save(); - $uri = $entity->urlInfo(); - $edit_link = \Drupal::l($this->t('Edit'), $uri['route_name'], $uri['route_parameters'], $uri['options']); + $edit_link = \Drupal::linkGenerator()->generateFromUrl($this->t('Edit'), $this->entity->urlInfo()); if ($status == SAVED_UPDATED) { drupal_set_message($this->t('Role %label has been updated.', array('%label' => $entity->label()))); watchdog('user', 'Role %label has been updated.', array('%label' => $entity->label()), WATCHDOG_NOTICE, $edit_link); diff --git a/core/modules/user/lib/Drupal/user/RoleListController.php b/core/modules/user/lib/Drupal/user/RoleListController.php index c2cd9b9..86af020 100644 --- a/core/modules/user/lib/Drupal/user/RoleListController.php +++ b/core/modules/user/lib/Drupal/user/RoleListController.php @@ -48,7 +48,7 @@ public function getOperations(EntityInterface $entity) { $operations['permissions'] = array( 'title' => t('Edit permissions'), 'weight' => 20, - ) + $entity->urlInfo('edit-permissions-form'); + ) + $entity->urlInfo('edit-permissions-form')->toArray(); } return $operations; } diff --git a/core/modules/user/user.module b/core/modules/user/user.module index 6dc8139..023884b 100644 --- a/core/modules/user/user.module +++ b/core/modules/user/user.module @@ -4,6 +4,7 @@ use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Session\AccountInterface; use \Drupal\Core\Entity\Display\EntityViewDisplayInterface; +use Drupal\Core\Url; use Drupal\file\Entity\File; use Drupal\user\Entity\User; use Drupal\user\UserInterface; @@ -150,12 +151,9 @@ function user_entity_bundle_info() { * Entity URI callback. */ function user_uri($user) { - return array( - 'route_name' => 'user.view', - 'route_parameters' => array( - 'user' => $user->id(), - ), - ); + return new Url('user.view', array( + 'user' => $user->id(), + )); } /** diff --git a/core/modules/views_ui/lib/Drupal/views_ui/ViewEditFormController.php b/core/modules/views_ui/lib/Drupal/views_ui/ViewEditFormController.php index 4993f7b..646e126 100644 --- a/core/modules/views_ui/lib/Drupal/views_ui/ViewEditFormController.php +++ b/core/modules/views_ui/lib/Drupal/views_ui/ViewEditFormController.php @@ -685,7 +685,7 @@ public function renderDisplayTop(ViewUI $view) { ), 'clone' => array( 'title' => $this->t('Clone view'), - ) + $view->urlInfo('clone'), + ) + $view->urlInfo('clone')->toArray(), 'reorder' => array( 'title' => $this->t('Reorder displays'), 'href' => "admin/structure/views/nojs/reorder-displays/{$view->id()}/$display_id", @@ -697,7 +697,7 @@ public function renderDisplayTop(ViewUI $view) { if ($view->access('delete')) { $element['extra_actions']['#links']['delete'] = array( 'title' => $this->t('Delete view'), - ) + $view->urlInfo('delete-form'); + ) + $view->urlInfo('delete-form')->toArray(); } // Let other modules add additional links here. diff --git a/core/modules/views_ui/lib/Drupal/views_ui/ViewFormControllerBase.php b/core/modules/views_ui/lib/Drupal/views_ui/ViewFormControllerBase.php index 38e8150..9c96b48 100644 --- a/core/modules/views_ui/lib/Drupal/views_ui/ViewFormControllerBase.php +++ b/core/modules/views_ui/lib/Drupal/views_ui/ViewFormControllerBase.php @@ -121,7 +121,7 @@ public function getDisplayTabs(ViewUI $view) { '#link' => array( 'title' => $this->getDisplayLabel($view, $id), 'localized_options' => array(), - ) + $view->urlInfo('edit-display-form'), + ) + $view->urlInfo('edit-display-form')->toArray(), ); $tabs[$id]['#link']['route_parameters']['display_id'] = $id; if (!empty($display['deleted'])) { diff --git a/core/modules/views_ui/lib/Drupal/views_ui/ViewListController.php b/core/modules/views_ui/lib/Drupal/views_ui/ViewListController.php index 62ffce8..3bf4aca 100644 --- a/core/modules/views_ui/lib/Drupal/views_ui/ViewListController.php +++ b/core/modules/views_ui/lib/Drupal/views_ui/ViewListController.php @@ -141,7 +141,7 @@ public function getOperations(EntityInterface $entity) { $operations['clone'] = array( 'title' => $this->t('Clone'), 'weight' => 15, - ) + $entity->urlInfo('clone'); + ) + $entity->urlInfo('clone')->toArray(); } // Add AJAX functionality to enable/disable operations. diff --git a/core/modules/views_ui/lib/Drupal/views_ui/ViewPreviewFormController.php b/core/modules/views_ui/lib/Drupal/views_ui/ViewPreviewFormController.php index ae9f4da..587bec2 100644 --- a/core/modules/views_ui/lib/Drupal/views_ui/ViewPreviewFormController.php +++ b/core/modules/views_ui/lib/Drupal/views_ui/ViewPreviewFormController.php @@ -90,9 +90,9 @@ public function form(array $form, array &$form_state) { '#markup' => $view->renderPreview($this->displayID, $args), ); } - $uri = $view->urlInfo('preview-form'); - $uri['route_parameters']['display_id'] = $this->displayID; - $form['#action'] = \Drupal::url($uri['route_name'], $uri['route_parameters'], $uri['options']); + $form['#action'] = $view->urlInfo('preview-form') + ->setRouteParameter('display_id', $this->displayID) + ->toString(); return $form; } diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityUrlTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityUrlTest.php index 96f482d..0e8a87e 100644 --- a/core/tests/Drupal/Tests/Core/Entity/EntityUrlTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/EntityUrlTest.php @@ -31,6 +31,11 @@ class EntityUrlTest extends UnitTestCase { protected $entityManager; /** + * @var \Drupal\Core\Routing\UrlGeneratorInterface|\PHPUnit_Framework_MockObject_MockObject + */ + protected $urlGenerator; + + /** * {@inheritdoc} */ public static function getInfo() { @@ -48,9 +53,11 @@ protected function setUp() { parent::setUp(); $this->entityManager = $this->getMock('Drupal\Core\Entity\EntityManagerInterface'); + $this->urlGenerator = $this->getMock('Drupal\Core\Routing\UrlGeneratorInterface'); $container = new ContainerBuilder(); $container->set('entity.manager', $this->entityManager); + $container->set('url_generator', $this->urlGenerator); \Drupal::setContainer($container); } @@ -87,8 +94,8 @@ public function testUrlInfo($entity_class, $link_template, $expected) { } if ($expected) { - $this->assertSame($expected, $uri['route_name']); - $this->assertSame($entity, $uri['options']['entity']); + $this->assertSame($expected, $uri->getRouteName()); + $this->assertSame($entity, $uri->getOption('entity')); } else { $this->assertEmpty($uri); @@ -150,9 +157,7 @@ public function testUrl() { $this->assertSame('', $no_link_entity->url('banana')); $valid_entity = new TestEntity(array('id' => 'test_entity_id'), 'test_entity_type'); - $url_generator = $this->getMock('Drupal\Core\Routing\UrlGeneratorInterface'); - $valid_entity->setUrlGenerator($url_generator); - $url_generator->expects($this->exactly(2)) + $this->urlGenerator->expects($this->exactly(2)) ->method('generateFromRoute') ->will($this->returnValueMap(array( array( @@ -195,8 +200,7 @@ public function testUrlForAdminForm() { ->with('test_entity_type') ->will($this->returnValue($entity_type)); - $url_generator = $this->getMock('Drupal\Core\Routing\UrlGeneratorInterface'); - $url_generator->expects($this->once()) + $this->urlGenerator->expects($this->once()) ->method('generateFromRoute') ->with('test_entity_type.admin_form', array( 'test_entity_type_bundle' => 'test_entity_bundle', @@ -205,7 +209,6 @@ public function testUrlForAdminForm() { ->will($this->returnValue('entity/test_entity_type/test_entity_bundle/test_entity_id')); $entity = new TestEntityWithBundle(array('id' => 'test_entity_id', 'bundle' => 'test_entity_bundle'), 'test_entity_type'); - $entity->setUrlGenerator($url_generator); $this->assertSame('entity/test_entity_type/test_entity_bundle/test_entity_id', $entity->url('admin-form')); } @@ -232,14 +235,12 @@ public function testGetSystemPath() { $no_link_entity = new TestEntity(array('id' => 'test_entity_id'), 'test_entity_type'); $this->assertSame('', $no_link_entity->getSystemPath('banana')); - $url_generator = $this->getMock('Drupal\Core\Routing\UrlGeneratorInterface'); - $url_generator->expects($this->once()) + $this->urlGenerator->expects($this->once()) ->method('getPathFromRoute') ->with('test_entity_type.view', array('test_entity_type' => 'test_entity_id')) ->will($this->returnValue('entity/test_entity_type/test_entity_id')); $valid_entity = new TestEntity(array('id' => 'test_entity_id'), 'test_entity_type'); - $valid_entity->setUrlGenerator($url_generator); $this->assertSame('entity/test_entity_type/test_entity_id', $valid_entity->getSystemPath()); } @@ -294,21 +295,9 @@ class TestConfigEntity extends ConfigEntityBase { class TestEntity extends Entity { - /** - * Sets the URL generator. - * - * @param \Drupal\Core\Routing\UrlGeneratorInterface $url_generator - * - * @return $this - */ - public function setUrlGenerator(UrlGeneratorInterface $url_generator) { - $this->urlGenerator = $url_generator; - return $this; - } - } -class TestEntityWithTemplates extends TestEntity { +class TestEntityWithTemplates extends Entity { /** * {@inheritdoc} @@ -321,7 +310,7 @@ protected function linkTemplates() { } -class TestEntityWithBundle extends TestEntity { +class TestEntityWithBundle extends Entity { /** * The entity bundle.