diff --git a/core/includes/menu.inc b/core/includes/menu.inc index 4f72878..f8766f1 100644 --- a/core/includes/menu.inc +++ b/core/includes/menu.inc @@ -8,6 +8,7 @@ use Drupal\Component\Utility\String; use Drupal\Core\Render\Element; use Drupal\Core\Template\Attribute; +use Drupal\Core\Url; /** * @defgroup menu Menu and routing system @@ -347,10 +348,9 @@ function template_preprocess_menu_local_task(&$variables) { '#options' => $link['localized_options'], ); - $variables['link'] += array( - '#route_name' => $link['route_name'], - '#route_parameters' => $link['route_parameters'], - ); + if (!isset($variables['link']['#url'])) { + $variables['link']['#url'] = $link['url']; + } } /** @@ -382,11 +382,10 @@ function template_preprocess_menu_local_action(&$variables) { ); // @todo Figure out how to support local actions without a href properly. - if ($link['href'] === '' && !empty($link['route_name'])) { - $variables['link'] += array( - '#route_name' => $link['route_name'], - '#route_parameters' => $link['route_parameters'], - ); + if ($link['href'] === '' && !empty($link['url'])) { + if (!isset($variables['link']['#url'])) { + $variables['link']['#url'] = $link['url']; + } } } diff --git a/core/includes/theme.inc b/core/includes/theme.inc index 5832b0a..9c01ba6 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -894,14 +894,8 @@ function template_preprocess_status_messages(&$variables) { * is used as its CSS class. Each link should be itself an array, with the * following elements: * - title: The link text. - * - route_name: (optional) The name of the route to link to. If omitted - * (and if 'href' is omitted as well), the 'title' is shown as - * a plain text item in the links list. - * - route_parameters: (optional) An array of route parameters for the link. - * - href: (optional) The link URL. It is preferred to use 'route_name' and - * 'route parameters' for internal links. Use 'href' for links to external - * URLs. If omitted (and if 'route_name' is omitted as well), the 'title' - * is shown as a plain text item in the links list. + * - url: (optional) The url object to link to. If omitted, no a tag is + * printed out. * - html: (optional) Whether or not 'title' is HTML. If set, the title * will not be passed through * \Drupal\Component\Utility\String::checkPlain(). @@ -978,8 +972,6 @@ function template_preprocess_links(&$variables) { foreach ($links as $key => $link) { $item = array(); $link += array( - 'route_name' => NULL, - 'route_parameters' => [], 'ajax' => NULL, 'url' => NULL, ); @@ -988,20 +980,18 @@ function template_preprocess_links(&$variables) { // Use the array key as class name. $li_attributes['class'][] = drupal_html_class($key); - $keys = array('title', 'url', 'route_name', 'route_parameters'); + $keys = array('title', 'url'); $link_element = array( '#type' => 'link', '#title' => $link['title'], '#options' => array_diff_key($link, array_combine($keys, $keys)), '#url' => $link['url'], - '#route_name' => $link['route_name'], - '#route_parameters' => $link['route_parameters'], '#ajax' => $link['ajax'], ); // Handle links and ensure that the active class is added on the LIs, but // only if the 'set_active_class' option is not empty. - if (isset($link['route_name']) || isset($link['url'])) { + if (isset($link['url'])) { if (!empty($variables['set_active_class'])) { // Also enable set_active_class for the contained link. @@ -1019,12 +1009,8 @@ function template_preprocess_links(&$variables) { $li_attributes['data-drupal-link-query'] = Json::encode($query); } - if (isset($link['url'])) { - $url = $link['url']; - } - elseif (isset($link['route_name'])) { - $url = Url::fromRoute($link['route_name'], $link['route_parameters']); - } + /** @var \Drupal\Core\Url $url */ + $url = $link['url']; // Add a "data-drupal-link-system-path" attribute to let the // drupal.active-link library know the path in a standardized manner. diff --git a/core/lib/Drupal/Core/Render/Element/Link.php b/core/lib/Drupal/Core/Render/Element/Link.php index 198c34d..fd0ddb1 100644 --- a/core/lib/Drupal/Core/Render/Element/Link.php +++ b/core/lib/Drupal/Core/Render/Element/Link.php @@ -37,11 +37,7 @@ public function getInfo() { * @param array $element * A structured array whose keys form the arguments to _l(): * - #title: The link text to pass as argument to _l(). - * - One of the following - * - #route_name and (optionally) a #route_parameters array; The route - * name and route parameters which will be passed into the link - * generator. - * - #href: The system path or URL to pass as argument to _l(). + * - #url: The URL info either pointing to a route or a non routed path. * - #options: (optional) An array of options to pass to _l() or the link * generator. * @@ -83,10 +79,6 @@ public static function preRenderLink($element) { $options = NestedArray::mergeDeep($element['#url']->getOptions(), $element['#options']); $element['#markup'] = \Drupal::l($element['#title'], $element['#url']->setOptions($options)); } - elseif (isset($element['#route_name'])) { - $element['#route_parameters'] = empty($element['#route_parameters']) ? array() : $element['#route_parameters']; - $element['#markup'] = \Drupal::l($element['#title'], new UrlObject($element['#route_name'], $element['#route_parameters'], $element['#options'])); - } return $element; } diff --git a/core/lib/Drupal/Core/Render/Element/Table.php b/core/lib/Drupal/Core/Render/Element/Table.php index 830f72e..08c539a 100644 --- a/core/lib/Drupal/Core/Render/Element/Table.php +++ b/core/lib/Drupal/Core/Render/Element/Table.php @@ -281,8 +281,7 @@ public static function validateTable(&$element, FormStateInterface $form_state, * $form['table'][$row]['edit'] = array( * '#type' => 'link', * '#title' => t('Edit'), - * '#route_name' => 'entity.test_entity.edit_form', - * '#route_parameters' => ['test_entity' => $row], + * '#url' => Url::fromRoute('entity.test_entity.edit_form', ['test_entity' => $row]), * ); * } * @endcode diff --git a/core/modules/aggregator/src/Controller/AggregatorController.php b/core/modules/aggregator/src/Controller/AggregatorController.php index a37a81d..a7e25ff 100644 --- a/core/modules/aggregator/src/Controller/AggregatorController.php +++ b/core/modules/aggregator/src/Controller/AggregatorController.php @@ -11,6 +11,7 @@ use Drupal\Core\Controller\ControllerBase; use Drupal\Core\Datetime\DateFormatter; use Drupal\aggregator\FeedInterface; +use Drupal\Core\Url; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -128,25 +129,21 @@ public function adminOverview() { $refresh_rate = $feed->getRefreshRate(); $row[] = ($last_checked ? $this->t('@time ago', array('@time' => $this->dateFormatter->formatInterval(REQUEST_TIME - $last_checked))) : $this->t('never')); $row[] = ($last_checked && $refresh_rate ? $this->t('%time left', array('%time' => $this->dateFormatter->formatInterval($last_checked + $refresh_rate - REQUEST_TIME))) : $this->t('never')); - $links['edit'] = array( + $links['edit'] = [ 'title' => $this->t('Edit'), - 'route_name' => 'entity.aggregator_feed.edit_form', - 'route_parameters' => array('aggregator_feed' => $feed->id()), - ); + 'url' => Url::fromRoute('entity.aggregator_feed.edit_form', ['aggregator_feed' => $feed->id()]), + ]; $links['delete'] = array( 'title' => $this->t('Delete'), - 'route_name' => 'entity.aggregator_feed.delete_form', - 'route_parameters' => array('aggregator_feed' => $feed->id()), + 'url' => Url::fromRoute('entity.aggregator_feed.delete_form', ['aggregator_feed' => $feed->id()]), ); $links['delete_items'] = array( 'title' => $this->t('Delete items'), - 'route_name' => 'aggregator.feed_items_delete', - 'route_parameters' => array('aggregator_feed' => $feed->id()), + 'url' => Url::fromRoute('aggregator.feed_items_delete', ['aggregator_feed' => $feed->id()]), ); $links['update'] = array( 'title' => $this->t('Update items'), - 'route_name' => 'aggregator.feed_refresh', - 'route_parameters' => array('aggregator_feed' => $feed->id()), + 'url' => Url::fromRoute('aggregator.feed_refresh', ['aggregator_feed' => $feed->id()]) ); $row[] = array( 'data' => array( diff --git a/core/modules/aggregator/src/FeedViewBuilder.php b/core/modules/aggregator/src/FeedViewBuilder.php index caea077..944d9a8 100644 --- a/core/modules/aggregator/src/FeedViewBuilder.php +++ b/core/modules/aggregator/src/FeedViewBuilder.php @@ -125,8 +125,7 @@ public function buildComponents(array &$build, array $entities, array $displays, '#title' => t('More posts about @title', array( '@title' => $title_stripped, )), - '#route_name' => 'entity.aggregator_feed.canonical', - '#route_parameters' => array('aggregator_feed' => $entity->id()), + '#url' => Url::fromRoute('entity.aggregator_feed.canonical', ['aggregator_feed' => $entity->id()]), '#options' => array( 'html' => TRUE, 'attributes' => array( diff --git a/core/modules/ban/src/Form/BanAdmin.php b/core/modules/ban/src/Form/BanAdmin.php index 94c1d4f..1690b91 100644 --- a/core/modules/ban/src/Form/BanAdmin.php +++ b/core/modules/ban/src/Form/BanAdmin.php @@ -10,6 +10,7 @@ use Drupal\Core\Form\FormBase; use Drupal\ban\BanIpManagerInterface; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Url; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -65,8 +66,7 @@ public function buildForm(array $form, FormStateInterface $form_state, $default_ $links = array(); $links['delete'] = array( 'title' => $this->t('Delete'), - 'route_name' => 'ban.delete', - 'route_parameters' => array('ban_id' => $ip->iid), + 'url' => Url::fromRoute('ban.delete', ['ban_id' => $ip->iid]), ); $row[] = array( 'data' => array( diff --git a/core/modules/block/src/BlockListBuilder.php b/core/modules/block/src/BlockListBuilder.php index e5da65d..1d11f99 100644 --- a/core/modules/block/src/BlockListBuilder.php +++ b/core/modules/block/src/BlockListBuilder.php @@ -16,6 +16,7 @@ use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Form\FormInterface; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Url; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\Request; @@ -356,11 +357,10 @@ public function buildForm(array $form, FormStateInterface $form_state) { } $form['place_blocks']['list'][$category_key]['content']['#links'][$plugin_id] = array( 'title' => $plugin_definition['admin_label'], - 'route_name' => 'block.admin_add', - 'route_parameters' => array( + 'url' => Url::fromRoute('block.admin_add', [ 'plugin_id' => $plugin_id, 'theme' => $this->theme - ), + ]), 'attributes' => array( 'class' => array('use-ajax', 'block-filter-text-source'), 'data-accepts' => 'application/vnd.drupal-modal', diff --git a/core/modules/book/book.admin.inc b/core/modules/book/book.admin.inc index ca559ba..ced19d9 100644 --- a/core/modules/book/book.admin.inc +++ b/core/modules/book/book.admin.inc @@ -8,6 +8,7 @@ use Drupal\Component\Utility\SafeMarkup; use Drupal\book\BookManager; use Drupal\Core\Render\Element; +use Drupal\Core\Url; /** * Returns HTML for a book administration form. @@ -45,20 +46,17 @@ function theme_book_admin_table($variables) { $links = array(); $links['view'] = array( 'title' => t('View'), - 'route_name' => 'entity.node.canonical', - 'route_parameters' => ['node' => $nid], + 'url' => Url::fromRoute('entity.node.canonical', ['node' => $nid]), ); if ($access) { $links['edit'] = array( 'title' => t('Edit'), - 'route_name' => 'entity.node.edit_form', - 'route_parameters' => array('node' => $nid), + 'url' => Url::fromRoute('entity.node.edit_form', ['node' => $nid]), 'query' => $destination, ); $links['delete'] = array( 'title' => t('Delete'), - 'route_name' => 'entity.node.delete_form', - 'route_parameters' => array('node' => $nid), + 'url' => Url::fromRoute('entity.node.delete_form', ['node' => $nid]), 'query' => $destination, ); } diff --git a/core/modules/book/book.module b/core/modules/book/book.module index 0240cc4..361fa1c 100644 --- a/core/modules/book/book.module +++ b/core/modules/book/book.module @@ -109,20 +109,17 @@ function book_node_links_alter(array &$node_links, NodeInterface $node, array &$ if (($account->hasPermission('add content to books') || $account->hasPermission('administer book outlines')) && $access_control_handler->createAccess($child_type) && $node->isPublished() && $node->book['depth'] < BookManager::BOOK_MAX_DEPTH) { $links['book_add_child'] = array( 'title' => t('Add child page'), - 'route_name' => 'node.add', - 'route_parameters' => ['node_type' => $child_type], - 'query' => array('parent' => $node->id()), + 'url' => Url::fromRoute('node.add', ['node_type' => $child_type], ['parent' => $node->id()]), ); } if ($account->hasPermission('access printer-friendly version')) { $links['book_printer'] = array( 'title' => t('Printer-friendly version'), - 'route_name' => 'book.export', - 'route_parameters' => [ + 'url' => Url::fromRoute('book.export', [ 'type' => 'html', 'node' => $node->id(), - ], + ]), 'attributes' => array('title' => t('Show a printer-friendly version of this book page and its sub-pages.')) ); } diff --git a/core/modules/book/src/Controller/BookController.php b/core/modules/book/src/Controller/BookController.php index 9e7a11f..7ba642f 100644 --- a/core/modules/book/src/Controller/BookController.php +++ b/core/modules/book/src/Controller/BookController.php @@ -10,6 +10,7 @@ use Drupal\book\BookExport; use Drupal\book\BookManagerInterface; use Drupal\Core\Controller\ControllerBase; +use Drupal\Core\Url; use Drupal\node\Entity\Node; use Drupal\node\NodeInterface; use Symfony\Component\DependencyInjection\Container; @@ -83,8 +84,7 @@ public function adminOverview() { $links = array(); $links['edit'] = array( 'title' => t('Edit order and titles'), - 'route_name' => 'book.admin_edit', - 'route_parameters' => array('node' => $book['nid']), + 'url' => Url::fromRoute('book.admin_edit', ['node' => $book['nid']]), ); $row[] = array( 'data' => array( diff --git a/core/modules/comment/comment.api.php b/core/modules/comment/comment.api.php index 13b2a4c..139f3e4 100644 --- a/core/modules/comment/comment.api.php +++ b/core/modules/comment/comment.api.php @@ -2,6 +2,7 @@ use Drupal\Core\Entity\EntityInterface; use Drupal\comment\CommentInterface; +use Drupal\Core\Url; /** * @file @@ -37,10 +38,8 @@ function hook_comment_links_alter(array &$links, CommentInterface $entity, array '#links' => array( 'comment-report' => array( 'title' => t('Report'), - 'route_name' => 'comment_test.report', - 'route_parameters' => ['comment' => $entity->id()], + 'url' => Url::fromRoute('comment_test.report', ['comment' => $entity->id()], ['query' => array('token' => \Drupal::getContainer()->get('csrf_token')->get("comment/{$entity->id()}/report"))]), 'html' => TRUE, - 'query' => array('token' => \Drupal::getContainer()->get('csrf_token')->get("comment/{$entity->id()}/report")), ), ), ); diff --git a/core/modules/comment/src/CommentLinkBuilder.php b/core/modules/comment/src/CommentLinkBuilder.php index 254ca04..5678966 100644 --- a/core/modules/comment/src/CommentLinkBuilder.php +++ b/core/modules/comment/src/CommentLinkBuilder.php @@ -13,6 +13,7 @@ use Drupal\Core\Session\AccountInterface; use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\StringTranslation\TranslationInterface; +use Drupal\Core\Url; /** * Defines a class for building markup for comment links on a commented entity. @@ -114,7 +115,7 @@ public function buildCommentedEntityLinks(ContentEntityInterface $entity, array if ($this->moduleHandler->moduleExists('history')) { $links['comment-new-comments'] = array( 'title' => '', - 'route_name' => '', + 'url' => Url::fromRoute(''), 'attributes' => array( 'class' => 'hidden', 'title' => $this->t('Jump to the first new comment of this posting.'), @@ -136,15 +137,14 @@ public function buildCommentedEntityLinks(ContentEntityInterface $entity, array 'fragment' => 'comment-form', ); if ($comment_form_location == CommentItemInterface::FORM_SEPARATE_PAGE) { - $links['comment-add']['route_name'] = 'comment.reply'; - $links['comment-add']['route_parameters'] = array( + $links['comment-add']['url'] = Url::fromRoute('comment.reply', [ 'entity_type' => $entity->getEntityTypeId(), 'entity' => $entity->id(), 'field_name' => $field_name, - ); + ]); } else { - $links['comment-add'] += $entity->urlInfo()->toArray(); + $links['comment-add'] += ['url' => $entity->urlInfo()]; } } elseif ($this->currentUser->isAnonymous()) { @@ -171,12 +171,11 @@ public function buildCommentedEntityLinks(ContentEntityInterface $entity, array 'fragment' => 'comment-form', ); if ($comment_form_location == CommentItemInterface::FORM_SEPARATE_PAGE) { - $links['comment-add']['route_name'] = 'comment.reply'; - $links['comment-add']['route_parameters'] = array( + $links['comment-add']['url'] = Url::fromRoute('comment.reply', [ 'entity_type' => $entity->getEntityTypeId(), 'entity' => $entity->id(), 'field_name' => $field_name, - ); + ]); } else { $links['comment-add'] += $entity->urlInfo()->toArray(); diff --git a/core/modules/comment/src/CommentViewBuilder.php b/core/modules/comment/src/CommentViewBuilder.php index da9ebbc..09399bf 100644 --- a/core/modules/comment/src/CommentViewBuilder.php +++ b/core/modules/comment/src/CommentViewBuilder.php @@ -17,6 +17,7 @@ use Drupal\Core\Entity\EntityViewBuilder; use Drupal\Core\Entity\Entity\EntityViewDisplay; use Drupal\Core\Language\LanguageManagerInterface; +use Drupal\Core\Url; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -261,21 +262,19 @@ protected static function buildLinks(CommentInterface $entity, EntityInterface $ if ($entity->access('create')) { $links['comment-reply'] = array( 'title' => t('Reply'), - 'route_name' => 'comment.reply', - 'route_parameters' => [ + 'url' => Url::fromRoute('comment.reply', [ 'entity_type' => $entity->getCommentedEntityTypeId(), 'entity' => $entity->getCommentedEntityId(), 'field_name' => $entity->getFieldName(), 'pid' => $entity->id(), - ], + ]), 'html' => TRUE, ); } if (!$entity->isPublished() && $entity->access('approve')) { $links['comment-approve'] = array( 'title' => t('Approve'), - 'route_name' => 'comment.approve', - 'route_parameters' => array('comment' => $entity->id()), + 'url' => Url::fromRoute('comment.approve', ['comment' => $entity->id()]), 'html' => TRUE, ); } diff --git a/core/modules/comment/src/Form/CommentAdminOverview.php b/core/modules/comment/src/Form/CommentAdminOverview.php index 68311d7..c68f54b 100644 --- a/core/modules/comment/src/Form/CommentAdminOverview.php +++ b/core/modules/comment/src/Form/CommentAdminOverview.php @@ -15,6 +15,7 @@ use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Form\FormBase; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Url; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -217,18 +218,12 @@ public function buildForm(array $form, FormStateInterface $form_state, $type = ' $links = array(); $links['edit'] = array( 'title' => $this->t('Edit'), - 'route_name' => 'entity.comment.edit_form', - 'route_parameters' => array('comment' => $comment->id()), - 'options' => $comment_uri_options, - 'query' => $destination, + 'url' => Url::fromRoute('entity.comment.edit_form', ['comment' => $comment->id()], $comment_uri_options + ['query' => $destination]), ); if ($this->moduleHandler->moduleExists('content_translation') && $this->moduleHandler->invoke('content_translation', 'translate_access', array($comment))->isAllowed()) { $links['translate'] = array( 'title' => $this->t('Translate'), - 'route_name' => 'content_translation.translation_overview_comment', - 'route_parameters' => array('comment' => $comment->id()), - 'options' => $comment_uri_options, - 'query' => $destination, + 'url' => Url::fromRoute('content_translation.translation_overview_comment', ['comment' => $comment->id()], $comment_uri_options + ['query' => $destination]), ); } $options[$comment->id()]['operations']['data'] = array( diff --git a/core/modules/comment/tests/modules/comment_test/comment_test.module b/core/modules/comment/tests/modules/comment_test/comment_test.module index 64ee3ad..797a5fd 100644 --- a/core/modules/comment/tests/modules/comment_test/comment_test.module +++ b/core/modules/comment/tests/modules/comment_test/comment_test.module @@ -7,6 +7,7 @@ */ use Drupal\comment\CommentInterface; +use Drupal\Core\Url; /** * Implements hook_entity_type_alter(). @@ -36,10 +37,8 @@ function comment_test_comment_links_alter(array &$links, CommentInterface &$enti '#links' => array( 'comment-report' => array( 'title' => t('Report'), - 'route_name' => 'comment_test.report', - 'route_parameters' => ['comment' => $entity->id()], + 'url' => Url::fromRoute('comment_test.report', ['comment' => $entity->id()], ['query' => array('token' => \Drupal::getContainer()->get('csrf_token')->get("comment/{$entity->id()}/report"))]), 'html' => TRUE, - 'query' => array('token' => \Drupal::getContainer()->get('csrf_token')->get("comment/{$entity->id()}/report")), ), ), ); diff --git a/core/modules/comment/tests/src/Unit/CommentLinkBuilderTest.php b/core/modules/comment/tests/src/Unit/CommentLinkBuilderTest.php index 2993f28..25d5c3c 100644 --- a/core/modules/comment/tests/src/Unit/CommentLinkBuilderTest.php +++ b/core/modules/comment/tests/src/Unit/CommentLinkBuilderTest.php @@ -9,6 +9,7 @@ use Drupal\comment\CommentLinkBuilder; use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface; +use Drupal\Core\Url; use Drupal\node\NodeInterface; use Drupal\simpletest\TestBase; use Drupal\Tests\UnitTestCase; @@ -236,11 +237,11 @@ public function getLinkCombinations() { $expected['comment-add'] = array('title' => 'Add new comment'); if ($combination['form_location'] == CommentItemInterface::FORM_BELOW) { // On the same page. - $expected['comment-add']['route_name'] = 'node.view'; + $expected['comment-add']['url'] = Url::fromRoute('node.view'); } else { // On a separate page. - $expected['comment-add']['route_name'] = 'comment.reply'; + $expected['comment-add']['url'] = Url::fromRoute('comment.reply'); } } } diff --git a/core/modules/config/src/Form/ConfigSync.php b/core/modules/config/src/Form/ConfigSync.php index 16bceed..b026e6f 100644 --- a/core/modules/config/src/Form/ConfigSync.php +++ b/core/modules/config/src/Form/ConfigSync.php @@ -20,6 +20,7 @@ use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Lock\LockBackendInterface; use Drupal\Core\Config\StorageComparer; +use Drupal\Core\Url; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -264,8 +265,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { } $links['view_diff'] = array( 'title' => $this->t('View differences'), - 'route_name' => $route_name, - 'route_parameters' => $route_options, + 'url' => Url::fromRoute($route_name, $route_options), 'attributes' => array( 'class' => array('use-ajax'), 'data-accepts' => 'application/vnd.drupal-modal', diff --git a/core/modules/config_translation/src/ConfigEntityMapper.php b/core/modules/config_translation/src/ConfigEntityMapper.php index 9265d33..2cbc78e 100644 --- a/core/modules/config_translation/src/ConfigEntityMapper.php +++ b/core/modules/config_translation/src/ConfigEntityMapper.php @@ -13,6 +13,7 @@ use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Routing\RouteProviderInterface; use Drupal\Core\StringTranslation\TranslationInterface; +use Drupal\Core\Url; use Drupal\locale\LocaleConfigManager; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\Request; @@ -216,10 +217,9 @@ public function getOperations() { return array( 'list' => array( 'title' => $this->t('List'), - 'route_name' => 'config_translation.entity_list', - 'route_parameters' => [ + 'url' => Url::fromRoute('config_translation.entity_list', [ 'mapper_id' => $this->getPluginId(), - ], + ]), ), ); } diff --git a/core/modules/config_translation/src/Controller/ConfigTranslationController.php b/core/modules/config_translation/src/Controller/ConfigTranslationController.php index 646d3b8..b6b016c 100644 --- a/core/modules/config_translation/src/Controller/ConfigTranslationController.php +++ b/core/modules/config_translation/src/Controller/ConfigTranslationController.php @@ -15,6 +15,7 @@ use Drupal\Core\PathProcessor\InboundPathProcessorInterface; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Session\AccountInterface; +use Drupal\Core\Url; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Matcher\RequestMatcherInterface; @@ -174,9 +175,7 @@ public function itemPage(Request $request, RouteMatchInterface $route_match, $pl if ($edit_access) { $operations['edit'] = array( 'title' => $this->t('Edit'), - 'route_name' => $mapper->getBaseRouteName(), - 'route_parameters' => $mapper->getBaseRouteParameters(), - 'query' => array('destination' => $mapper->getOverviewPath()), + 'url' => Url::fromRoute($mapper->getBaseRouteName(), $mapper->getBaseRouteParameters(), ['query' => ['destination' => $mapper->getOverviewPath()]]), ); } } @@ -188,22 +187,19 @@ public function itemPage(Request $request, RouteMatchInterface $route_match, $pl if (!$mapper->hasTranslation($language)) { $operations['add'] = array( 'title' => $this->t('Add'), - 'route_name' => $mapper->getAddRouteName(), - 'route_parameters' => $mapper->getAddRouteParameters(), + 'url' => Url::fromRoute($mapper->getAddRouteName(), $mapper->getAddRouteParameters()), ); } else { // Otherwise, link to edit the existing translation. $operations['edit'] = array( 'title' => $this->t('Edit'), - 'route_name' => $mapper->getEditRouteName(), - 'route_parameters' => $mapper->getEditRouteParameters(), + 'url' => Url::fromRoute($mapper->getEditRouteName(), $mapper->getEditRouteParameters()), ); $operations['delete'] = array( 'title' => $this->t('Delete'), - 'route_name' => $mapper->getDeleteRouteName(), - 'route_parameters' => $mapper->getDeleteRouteParameters(), + 'url' => Url::fromRoute($mapper->getDeleteRouteName(), $mapper->getDeleteRouteParameters()), ); } } diff --git a/core/modules/contextual/src/Element/ContextualLinks.php b/core/modules/contextual/src/Element/ContextualLinks.php index 8aeec9f..3c95191 100644 --- a/core/modules/contextual/src/Element/ContextualLinks.php +++ b/core/modules/contextual/src/Element/ContextualLinks.php @@ -8,6 +8,7 @@ namespace Drupal\contextual\Element; use Drupal\Core\Render\Element\RenderElement; +use Drupal\Core\Url; /** * Provides a contextual_links element. @@ -82,8 +83,7 @@ public static function preRenderLinks(array $element) { $class = drupal_html_class($class); $links[$class] = array( 'title' => $item['title'], - 'route_name' => isset($item['route_name']) ? $item['route_name'] : '', - 'route_parameters' => isset($item['route_parameters']) ? $item['route_parameters'] : array(), + 'url' => Url::fromRoute(isset($item['route_name']) ? $item['route_name'] : '', isset($item['route_parameters']) ? $item['route_parameters'] : array()), ); } $element['#links'] = $links; diff --git a/core/modules/field_ui/src/FieldOverview.php b/core/modules/field_ui/src/FieldOverview.php index 0e42fcd..838c116 100644 --- a/core/modules/field_ui/src/FieldOverview.php +++ b/core/modules/field_ui/src/FieldOverview.php @@ -14,6 +14,7 @@ use Drupal\Core\Field\FieldTypePluginManagerInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Render\Element; +use Drupal\Core\Url; use Drupal\field_ui\OverviewBase; use Symfony\Component\DependencyInjection\ContainerInterface; use Drupal\field\Entity\FieldStorageConfig; @@ -135,8 +136,7 @@ public function buildForm(array $form, FormStateInterface $form_state, $entity_t 'type' => array( '#type' => 'link', '#title' => $field_types[$field_storage->getType()]['label'], - '#route_name' => 'field_ui.storage_edit_' . $this->entity_type, - '#route_parameters' => $route_parameters, + '#url' => Url::fromRoute('field_ui.storage_edit_' . $this->entity_type, $route_parameters), '#options' => array('attributes' => array('title' => $this->t('Edit field settings.'))), ), ); diff --git a/core/modules/forum/forum.module b/core/modules/forum/forum.module index bd4da4e..aa8dfc5 100644 --- a/core/modules/forum/forum.module +++ b/core/modules/forum/forum.module @@ -52,8 +52,7 @@ function forum_help($route_name, RouteMatchInterface $route_match) { $output = '

' . t('Forums contain forum topics. Use containers to group related forums.') . '

'; $more_help_link = array( '#type' => 'link', - '#route_name' => 'help.page', - '#route_parameters' => array('name' => 'forum'), + '#url' => Url::fromRoute('help.page', ['name' => 'forum']), '#title' => t('More help'), ); $container = array( @@ -118,8 +117,7 @@ function forum_menu_local_tasks(&$data, $route_name) { '#theme' => 'menu_local_action', '#link' => array( 'title' => t('Add new @node_type', array('@node_type' => entity_load('node_type', $type)->label())), - 'route_name' => 'node.add', - 'route_parameters' => ['node_type' => $type], + 'url' => Url::fromRoute('node.add', ['node_type' => $type]), ), ); if ($forum_term && $forum_term->bundle() == $vid) { diff --git a/core/modules/forum/src/Form/Overview.php b/core/modules/forum/src/Form/Overview.php index d897881..ceaa4d3 100644 --- a/core/modules/forum/src/Form/Overview.php +++ b/core/modules/forum/src/Form/Overview.php @@ -70,14 +70,14 @@ public function buildForm(array $form, FormStateInterface $form_state) { unset($form['terms'][$key]['operations']['#links']['delete']); if (!empty($term->forum_container->value)) { $form['terms'][$key]['operations']['#links']['edit']['title'] = $this->t('edit container'); - $form['terms'][$key]['operations']['#links']['edit']['route_name'] = 'forum.edit_container'; + $form['terms'][$key]['operations']['#links']['edit']['url'] = Url::fromRoute('forum.edit_container'); // We don't want the redirect from the link so we can redirect the // delete action. unset($form['terms'][$key]['operations']['#links']['edit']['query']['destination']); } else { $form['terms'][$key]['operations']['#links']['edit']['title'] = $this->t('edit forum'); - $form['terms'][$key]['operations']['#links']['edit']['route_name'] = 'forum.edit_forum'; + $form['terms'][$key]['operations']['#links']['edit']['route_name'] = Url::fromRoute('forum.edit_forum'); // We don't want the redirect from the link so we can redirect the // delete action. unset($form['terms'][$key]['operations']['#links']['edit']['query']['destination']); diff --git a/core/modules/forum/src/Plugin/Block/ForumBlockBase.php b/core/modules/forum/src/Plugin/Block/ForumBlockBase.php index edd7ac6..17c3147 100644 --- a/core/modules/forum/src/Plugin/Block/ForumBlockBase.php +++ b/core/modules/forum/src/Plugin/Block/ForumBlockBase.php @@ -11,6 +11,7 @@ use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Session\AccountInterface; use Drupal\Core\Cache\Cache; +use Drupal\Core\Url; /** * Provides a base class for Forum blocks. @@ -27,7 +28,7 @@ public function build() { $elements['forum_list'] = $node_title_list; $elements['forum_more'] = array( '#type' => 'more_link', - '#route_name' => 'forum.index', + '#url' => Url::fromRoute('forum.index'), '#attributes' => array('title' => $this->t('Read the latest forum topics.')), ); } diff --git a/core/modules/image/src/Form/ImageStyleEditForm.php b/core/modules/image/src/Form/ImageStyleEditForm.php index 1b28d7f..4edd31c 100644 --- a/core/modules/image/src/Form/ImageStyleEditForm.php +++ b/core/modules/image/src/Form/ImageStyleEditForm.php @@ -10,6 +10,7 @@ use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Url; use Drupal\image\ConfigurableImageEffectInterface; use Drupal\image\ImageEffectManager; use Drupal\Component\Utility\String; @@ -126,20 +127,18 @@ public function form(array $form, FormStateInterface $form_state) { if ($is_configurable) { $links['edit'] = array( 'title' => $this->t('Edit'), - 'route_name' => 'image.effect_edit_form', - 'route_parameters' => [ + 'url' => Url::fromRoute('image.effect_edit_form', [ 'image_style' => $this->entity->id(), 'image_effect' => $key, - ], + ]), ); } $links['delete'] = array( 'title' => $this->t('Delete'), - 'route_name' => 'image.effect_delete', - 'route_parameters' => [ + 'url' => Url::fromRoute('image.effect_delete', [ 'image_style' => $this->entity->id(), 'image_effect' => $key, - ], + ]), ); $form['effects'][$key]['operations'] = array( '#type' => 'operations', diff --git a/core/modules/language/language.admin.inc b/core/modules/language/language.admin.inc index b060d35..d7a0415 100644 --- a/core/modules/language/language.admin.inc +++ b/core/modules/language/language.admin.inc @@ -8,6 +8,7 @@ use Drupal\Component\Utility\String; use Drupal\Core\Render\Element; use Drupal\Core\Template\Attribute; +use Drupal\Core\Url; /** * Prepares variables for language negotiation configuration form. @@ -113,8 +114,7 @@ function theme_language_negotiation_configure_browser_form_table($variables) { $links = array(); $links['delete'] = array( 'title' => t('Delete'), - 'route_name' => 'language.negotiation_browser_delete', - 'route_parameters' => ['browser_langcode' => $key], + 'url' => Url::fromRoute('language.negotiation_browser_delete', ['browser_langcode' => $key]), 'attributes' => array( 'class' => array('image-style-link'), ), diff --git a/core/modules/language/src/Form/NegotiationConfigureForm.php b/core/modules/language/src/Form/NegotiationConfigureForm.php index 5b2b471..c7495e9 100644 --- a/core/modules/language/src/Form/NegotiationConfigureForm.php +++ b/core/modules/language/src/Form/NegotiationConfigureForm.php @@ -16,6 +16,7 @@ use Drupal\Core\Extension\ThemeHandlerInterface; use Drupal\Core\Form\FormBase; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Url; use Drupal\language\ConfigurableLanguageManagerInterface; use Drupal\language\LanguageNegotiatorInterface; use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationSelected; @@ -298,7 +299,7 @@ protected function configureFormTable(array &$form, $type) { if (isset($method['config_route_name'])) { $config_op['configure'] = array( 'title' => $this->t('Configure'), - 'route_name' => $method['config_route_name'], + 'url' => Url::fromRoute($method['config_route_name']), ); // If there is at least one operation enabled show the operation // column. diff --git a/core/modules/node/src/Controller/NodeController.php b/core/modules/node/src/Controller/NodeController.php index 64fc4f6..27ee85d 100644 --- a/core/modules/node/src/Controller/NodeController.php +++ b/core/modules/node/src/Controller/NodeController.php @@ -184,16 +184,14 @@ public function revisionOverview(NodeInterface $node) { if ($revert_permission) { $links['revert'] = array( 'title' => $this->t('Revert'), - 'route_name' => 'node.revision_revert_confirm', - 'route_parameters' => array('node' => $node->id(), 'node_revision' => $vid), + 'url' => Url::fromRoute('node.revision_revert_confirm', array('node' => $node->id(), 'node_revision' => $vid)), ); } if ($delete_permission) { $links['delete'] = array( 'title' => $this->t('Delete'), - 'route_name' => 'node.revision_delete_confirm', - 'route_parameters' => array('node' => $node->id(), 'node_revision' => $vid), + 'url' => Url::fromRoute('node.revision_delete_confirm', array('node' => $node->id(), 'node_revision' => $vid)), ); } diff --git a/core/modules/path/src/Controller/PathController.php b/core/modules/path/src/Controller/PathController.php index 96dd34b..65c1eb4 100644 --- a/core/modules/path/src/Controller/PathController.php +++ b/core/modules/path/src/Controller/PathController.php @@ -10,6 +10,7 @@ use Drupal\Core\Controller\ControllerBase; use Drupal\Core\Path\AliasStorageInterface; use Drupal\Core\Path\AliasManagerInterface; +use Drupal\Core\Url; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -87,19 +88,11 @@ public function adminOverview($keys) { $operations = array(); $operations['edit'] = array( 'title' => $this->t('Edit'), - 'route_name' => 'path.admin_edit', - 'route_parameters' => array( - 'pid' => $data->pid, - ), - 'query' => $destination, + 'url' => Url::fromRoute('path.admin_edit', ['pid' => $data->pid], ['query' => $destination]), ); $operations['delete'] = array( 'title' => $this->t('Delete'), - 'route_name' => 'path.delete', - 'route_parameters' => array( - 'pid' => $data->pid, - ), - 'query' => $destination, + 'url' => Url::fromRoute('path.delete', ['pid' => $data->pid], ['query' => $destination]); ); $row['data']['operations'] = array( 'data' => array( diff --git a/core/modules/search/src/SearchPageListBuilder.php b/core/modules/search/src/SearchPageListBuilder.php index 5714f0a..4333064 100644 --- a/core/modules/search/src/SearchPageListBuilder.php +++ b/core/modules/search/src/SearchPageListBuilder.php @@ -14,6 +14,7 @@ use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Form\FormInterface; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Url; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -118,7 +119,7 @@ public function buildRow(EntityInterface $entity) { $row['url'] = array( '#type' => 'link', '#title' => $row['url'], - '#route_name' => 'search.view_' . $entity->id(), + '#url' => Url::fromRoute('search.view_' . $entity->id()), ); } @@ -305,10 +306,9 @@ public function getDefaultOperations(EntityInterface $entity) { else { $operations['default'] = array( 'title' => $this->t('Set as default'), - 'route_name' => 'entity.search_page.set_default', - 'route_parameters' => array( + 'url' => Url::fromRoute('entity.search_page.set_default', array( 'search_page' => $entity->id(), - ), + )), 'weight' => 50, ); } diff --git a/core/modules/shortcut/shortcut.module b/core/modules/shortcut/shortcut.module index ba20e0b..8150bf2 100644 --- a/core/modules/shortcut/shortcut.module +++ b/core/modules/shortcut/shortcut.module @@ -343,8 +343,7 @@ function shortcut_preprocess_page(&$variables) { '#prefix' => '', ); @@ -367,8 +366,7 @@ function shortcut_toolbar() { $configure_link = array( '#type' => 'link', '#title' => t('Edit shortcuts'), - '#route_name' => 'entity.shortcut_set.customize_form', - '#route_parameters' => array('shortcut_set' => $shortcut_set->id()), + '#url' => Url::fromRoute('entity.shortcut_set.customize_form', ['shortcut_set' => $shortcut_set->id()]) '#options' => array('attributes' => array('class' => array('edit-shortcuts'))), ); } diff --git a/core/modules/system/src/Form/ModulesListForm.php b/core/modules/system/src/Form/ModulesListForm.php index b24f8ca..aaf73eb 100644 --- a/core/modules/system/src/Form/ModulesListForm.php +++ b/core/modules/system/src/Form/ModulesListForm.php @@ -302,8 +302,7 @@ protected function buildRow(array $modules, Extension $module, $distribution) { $row['links']['configure'] = array( '#type' => 'link', '#title' => $this->t('Configure'), - '#route_name' => $module->info['configure'], - '#route_parameters' => $route_parameters, + '#url' => Url::fromRoute($module->info['configure'], $route_parameters), '#options' => array( 'attributes' => array( 'class' => array('module-link', 'module-link-configure'), diff --git a/core/modules/system/src/Tests/Common/RenderElementTypesTest.php b/core/modules/system/src/Tests/Common/RenderElementTypesTest.php index 73879ee..f3f27ab 100644 --- a/core/modules/system/src/Tests/Common/RenderElementTypesTest.php +++ b/core/modules/system/src/Tests/Common/RenderElementTypesTest.php @@ -146,7 +146,7 @@ function testMoreLink() { 'name' => "#type 'more_link' anchor tag with a relative path", 'value' => array( '#type' => 'more_link', - '#route_name' => 'router_test.1', + '#url' => Url::fromRoute('router_test.1'), ), 'expected' => '//div[@class="more-link"]/a[@href="' . _url('router_test/test1') . '" and text()="More"]', ), @@ -154,8 +154,7 @@ function testMoreLink() { 'name' => "#type 'more_link' anchor tag with a route", 'value' => array( '#type' => 'more_link', - '#route_name' => 'router_test.1', - '#route_parameters' => array(), + '#url' => Url::fromRoute('router_test.1'), ), 'expected' => '//div[@class="more-link"]/a[@href="' . \Drupal::urlGenerator()->generate('router_test.1') . '" and text()="More"]', ), @@ -163,7 +162,7 @@ function testMoreLink() { 'name' => "#type 'more_link' anchor tag with an absolute path", 'value' => array( '#type' => 'more_link', - '#route_name' => 'system.admin_content', + '#url' => Url::fromRoute('system.admin_content'), '#options' => array('absolute' => TRUE), ), 'expected' => '//div[@class="more-link"]/a[@href="' . _url('admin/content', array('absolute' => TRUE)) . '" and text()="More"]', @@ -172,7 +171,7 @@ function testMoreLink() { 'name' => "#type 'more_link' anchor tag to the front page", 'value' => array( '#type' => 'more_link', - '#route_name' => '', + '#url' => Url::fromRoute(''), ), 'expected' => '//div[@class="more-link"]/a[@href="' . _url('') . '" and text()="More"]', ), diff --git a/core/modules/system/src/Tests/Common/RenderWebTest.php b/core/modules/system/src/Tests/Common/RenderWebTest.php index 5e44ec0..5d7f36e 100644 --- a/core/modules/system/src/Tests/Common/RenderWebTest.php +++ b/core/modules/system/src/Tests/Common/RenderWebTest.php @@ -106,7 +106,7 @@ function testDrupalRenderFormElements() { $element = array( '#type' => 'link', '#title' => $this->randomMachineName(), - '#route_name' => 'common_test.destination', + '#url' => Url::fromRoute('common_test.destination'), '#options' => array( 'absolute' => TRUE, ), diff --git a/core/modules/system/system.api.php b/core/modules/system/system.api.php index c872f4b..0c569c4 100644 --- a/core/modules/system/system.api.php +++ b/core/modules/system/system.api.php @@ -412,12 +412,12 @@ function hook_menu_local_tasks(&$data, $route_name) { '#theme' => 'menu_local_action', '#link' => array( 'title' => t('Add content'), - 'route_name' => 'node.add_page', - 'localized_options' => array( + 'url' => Url::fromRoute('node.add_page', array( 'attributes' => array( 'title' => t('Add content'), ), - ), + )), + 'localized_options' => , ), ); diff --git a/core/modules/system/tests/modules/theme_test/src/EventSubscriber/ThemeTestSubscriber.php b/core/modules/system/tests/modules/theme_test/src/EventSubscriber/ThemeTestSubscriber.php index 7d2cb79..b4e4393 100644 --- a/core/modules/system/tests/modules/theme_test/src/EventSubscriber/ThemeTestSubscriber.php +++ b/core/modules/system/tests/modules/theme_test/src/EventSubscriber/ThemeTestSubscriber.php @@ -7,6 +7,7 @@ namespace Drupal\theme_test\EventSubscriber; +use Drupal\Core\Url; use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\HttpKernel\Event\GetResponseEvent; use Symfony\Component\EventDispatcher\EventSubscriberInterface; @@ -44,7 +45,7 @@ public function onRequest(GetResponseEvent $event) { // returning output and theming the page as a whole. $more_link = array( '#type' => 'more_link', - '#route_name' => 'user.page', + '#url' => Url::fromRoute('user.page'), '#attributes' => array('title' => 'Themed output generated in a KernelEvents::REQUEST listener'), ); $GLOBALS['theme_test_output'] = drupal_render($more_link); diff --git a/core/modules/toolbar/src/Element/ToolbarItem.php b/core/modules/toolbar/src/Element/ToolbarItem.php index e1249b9..29efe32 100644 --- a/core/modules/toolbar/src/Element/ToolbarItem.php +++ b/core/modules/toolbar/src/Element/ToolbarItem.php @@ -9,6 +9,7 @@ use Drupal\Component\Utility\Html; use Drupal\Core\Render\Element\RenderElement; +use Drupal\Core\Url; /** * Provides a toolbar item that is wrapped in markup for common styling. @@ -33,7 +34,7 @@ public function getInfo() { 'tab' => array( '#type' => 'link', '#title' => NULL, - '#route_name' => '', + '#url' => Url::fromRoute(''), ), ); } diff --git a/core/modules/toolbar/tests/modules/toolbar_test/toolbar_test.module b/core/modules/toolbar/tests/modules/toolbar_test/toolbar_test.module index deda1d1..9d4e89f 100644 --- a/core/modules/toolbar/tests/modules/toolbar_test/toolbar_test.module +++ b/core/modules/toolbar/tests/modules/toolbar_test/toolbar_test.module @@ -17,7 +17,7 @@ function toolbar_test_toolbar() { 'tab' => array( '#type' => 'link', '#title' => t('Test tab'), - '#route_name' => '', + '#url' => Url::fromRoute(''), '#options' => array( 'html' => FALSE, 'attributes' => array( diff --git a/core/modules/views_ui/src/Form/Ajax/ReorderDisplays.php b/core/modules/views_ui/src/Form/Ajax/ReorderDisplays.php index df08109..72dae7c 100644 --- a/core/modules/views_ui/src/Form/Ajax/ReorderDisplays.php +++ b/core/modules/views_ui/src/Form/Ajax/ReorderDisplays.php @@ -121,7 +121,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { 'link' => array( '#type' => 'link', '#title' => '' . $this->t('Remove') . '', - '#route_name' => '', + '#url' => Url::fromRoute(''), '#options' => array( 'html' => TRUE, ),