diff --git a/core/includes/menu.inc b/core/includes/menu.inc index f8766f1..85c1faf 100644 --- a/core/includes/menu.inc +++ b/core/includes/menu.inc @@ -8,7 +8,6 @@ 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 @@ -342,15 +341,13 @@ function template_preprocess_menu_local_task(&$variables) { } $link['localized_options']['set_active_class'] = TRUE; + $variables['link'] = array( '#type' => 'link', '#title' => $link_text, + '#url' => $link['url'], '#options' => $link['localized_options'], ); - - if (!isset($variables['link']['#url'])) { - $variables['link']['#url'] = $link['url']; - } } /** @@ -367,9 +364,7 @@ function template_preprocess_menu_local_task(&$variables) { function template_preprocess_menu_local_action(&$variables) { $link = $variables['element']['#link']; $link += array( - 'href' => '', 'localized_options' => array(), - 'route_parameters' => array(), ); $link['localized_options']['attributes']['class'][] = 'button'; $link['localized_options']['attributes']['class'][] = 'button-action'; @@ -379,14 +374,8 @@ function template_preprocess_menu_local_action(&$variables) { '#type' => 'link', '#title' => $link['title'], '#options' => $link['localized_options'], + '#url' => $link['url'], ); - - // @todo Figure out how to support local actions without a href properly. - 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 88d6d7f..66e506c 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -24,7 +24,6 @@ use Drupal\Core\Theme\ThemeSettings; use Drupal\Component\Utility\NestedArray; use Drupal\Core\Render\Element; -use Drupal\Core\Url; use Symfony\Component\HttpFoundation\Request; /** diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityListBuilder.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityListBuilder.php index 01fb7dd..a0ecdcf 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityListBuilder.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityListBuilder.php @@ -41,13 +41,15 @@ public function getDefaultOperations(EntityInterface $entity) { $operations['enable'] = array( 'title' => t('Enable'), 'weight' => -10, - ) + $entity->urlInfo('enable')->toArray(); + 'url' => $entity->urlInfo('enable'), + ); } elseif ($entity->hasLinkTemplate('disable')) { $operations['disable'] = array( 'title' => t('Disable'), 'weight' => 40, - ) + $entity->urlInfo('disable')->toArray(); + 'url' => $entity->urlInfo('disable'), + ); } } diff --git a/core/lib/Drupal/Core/Entity/EntityListBuilder.php b/core/lib/Drupal/Core/Entity/EntityListBuilder.php index eee643b..9e41b08 100644 --- a/core/lib/Drupal/Core/Entity/EntityListBuilder.php +++ b/core/lib/Drupal/Core/Entity/EntityListBuilder.php @@ -118,13 +118,15 @@ protected function getDefaultOperations(EntityInterface $entity) { $operations['edit'] = array( 'title' => $this->t('Edit'), 'weight' => 10, - ) + $entity->urlInfo('edit-form')->toArray(); + 'url' => $entity->urlInfo('edit-form'), + ); } if ($entity->access('delete') && $entity->hasLinkTemplate('delete-form')) { $operations['delete'] = array( 'title' => $this->t('Delete'), 'weight' => 100, - ) + $entity->urlInfo('delete-form')->toArray(); + 'url' => $entity->urlInfo('delete-form'), + ); } return $operations; diff --git a/core/lib/Drupal/Core/Form/ConfirmFormHelper.php b/core/lib/Drupal/Core/Form/ConfirmFormHelper.php index afa779a..5147407 100644 --- a/core/lib/Drupal/Core/Form/ConfirmFormHelper.php +++ b/core/lib/Drupal/Core/Form/ConfirmFormHelper.php @@ -34,18 +34,18 @@ public static function buildCancelLink(ConfirmFormInterface $form, Request $requ // If a destination is specified, that serves as the cancel link. if ($query->has('destination')) { $options = UrlHelper::parse($query->get('destination')); - $link = array( - '#url' => Url::fromUri('base://' . $options['path'], $options), - ); + $url = Url::fromUri('base://' . $options['path'], $options); } // Check for a route-based cancel link. - elseif ($url = $form->getCancelUrl()) { - $link = $url->toRenderArray(); + else { + $url = $form->getCancelUrl(); } - $link['#type'] = 'link'; - $link['#title'] = $form->getCancelText(); - return $link; + return [ + '#type' => 'link', + '#title' => $form->getCancelText(), + '#url' => $url, + ]; } } diff --git a/core/lib/Drupal/Core/Menu/LocalActionManager.php b/core/lib/Drupal/Core/Menu/LocalActionManager.php index 2e4eb92..68550bc 100644 --- a/core/lib/Drupal/Core/Menu/LocalActionManager.php +++ b/core/lib/Drupal/Core/Menu/LocalActionManager.php @@ -16,6 +16,7 @@ use Drupal\Core\Plugin\Discovery\YamlDiscovery; use Drupal\Core\Plugin\Factory\ContainerFactory; use Drupal\Core\Routing\RouteProviderInterface; +use Drupal\Core\Url; use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface; use Drupal\Core\Session\AccountInterface; @@ -166,8 +167,7 @@ public function getActionsForRoute($route_appears) { '#theme' => 'menu_local_action', '#link' => array( 'title' => $this->getTitle($plugin), - 'route_name' => $route_name, - 'route_parameters' => $route_parameters, + 'url' => Url::fromRoute($route_name, $route_parameters), 'localized_options' => $plugin->getOptions($request), ), '#access' => $this->accessManager->checkNamedRoute($route_name, $route_parameters, $this->account), diff --git a/core/lib/Drupal/Core/Menu/LocalTaskManager.php b/core/lib/Drupal/Core/Menu/LocalTaskManager.php index 3914d8e..5b85d7f 100644 --- a/core/lib/Drupal/Core/Menu/LocalTaskManager.php +++ b/core/lib/Drupal/Core/Menu/LocalTaskManager.php @@ -21,6 +21,7 @@ use Drupal\Core\Routing\RouteBuilderInterface; use Drupal\Core\Routing\RouteProviderInterface; use Drupal\Core\Session\AccountInterface; +use Drupal\Core\Url; use Symfony\Component\HttpFoundation\RequestStack; /** @@ -306,8 +307,7 @@ public function getTasksBuild($current_route_name) { $link = array( 'title' => $this->getTitle($child), - 'route_name' => $route_name, - 'route_parameters' => $route_parameters, + 'url' => Url::fromRoute($route_name, $route_parameters), 'localized_options' => $child->getOptions($request), ); $build[$level][$plugin_id] = array( diff --git a/core/lib/Drupal/Core/Menu/MenuLinkInterface.php b/core/lib/Drupal/Core/Menu/MenuLinkInterface.php index fdc61df..ffef255 100644 --- a/core/lib/Drupal/Core/Menu/MenuLinkInterface.php +++ b/core/lib/Drupal/Core/Menu/MenuLinkInterface.php @@ -218,9 +218,9 @@ public function getFormClass(); /** * Returns route information for a route to delete the menu link. * - * @return array|null - * An array with keys route_name and route_parameters, or NULL if there is - * no route (e.g. when the link is not deletable). + * @return \Drupal\Core\Url|null + * A Url object, or NULL if there is no route (e.g. when the link is not + * deletable). */ public function getDeleteRoute(); @@ -231,18 +231,18 @@ public function getDeleteRoute(); * they need to define additional local tasks, local actions, etc. that are * visible from the edit form. * - * @return array|null - * An array with keys route_name and route_parameters, or NULL if there is - * no route because there is no custom edit route for this instance. + * @return \Drupal\Core\Url|null + * A Url object, or NULL if there is no route because there is no custom + * edit route for this instance. */ public function getEditRoute(); /** * Returns route information for a route to translate the menu link. * - * @return array - * An array with keys route_name and route_parameters, or NULL if there is - * no route (e.g. when the link is not translatable). + * @return \Drupal\Core\Url|null + * A Url object, or NULL if there is no route (e.g. when the link is not + * translatable). */ public function getTranslateRoute(); diff --git a/core/lib/Drupal/Core/Render/Element/Link.php b/core/lib/Drupal/Core/Render/Element/Link.php index fd0ddb1..b785bd6 100644 --- a/core/lib/Drupal/Core/Render/Element/Link.php +++ b/core/lib/Drupal/Core/Render/Element/Link.php @@ -8,7 +8,6 @@ namespace Drupal\Core\Render\Element; use Drupal\Component\Utility\NestedArray; -use Drupal\Core\Url as UrlObject; /** * Provides a link render element. diff --git a/core/lib/Drupal/Core/Url.php b/core/lib/Drupal/Core/Url.php index 8361be7..85b0944 100644 --- a/core/lib/Drupal/Core/Url.php +++ b/core/lib/Drupal/Core/Url.php @@ -458,20 +458,10 @@ public function toString() { * An associative array containing all the properties of the route. */ public function toArray() { - if ($this->unrouted) { - return array( - // @todo Change 'path' to 'href': https://www.drupal.org/node/2347025. - 'path' => $this->getUri(), - 'options' => $this->getOptions(), - ); - } - else { - return array( - 'route_name' => $this->getRouteName(), - 'route_parameters' => $this->getRouteParameters(), - 'options' => $this->getOptions(), - ); - } + return [ + 'url' => $this, + 'options' => $this->getOptions(), + ]; } /** diff --git a/core/modules/comment/src/CommentLinkBuilder.php b/core/modules/comment/src/CommentLinkBuilder.php index 406aac4..f689b1a 100644 --- a/core/modules/comment/src/CommentLinkBuilder.php +++ b/core/modules/comment/src/CommentLinkBuilder.php @@ -111,7 +111,8 @@ public function buildCommentedEntityLinks(FieldableEntityInterface $entity, arra 'title' => $this->formatPlural($entity->get($field_name)->comment_count, '1 comment', '@count comments'), 'attributes' => array('title' => $this->t('Jump to the first comment of this posting.')), 'fragment' => 'comments', - ) + $entity->urlInfo()->toArray(); + 'url' => $entity->urlInfo(), + ); if ($this->moduleHandler->moduleExists('history')) { $links['comment-new-comments'] = array( 'title' => '', @@ -178,7 +179,7 @@ public function buildCommentedEntityLinks(FieldableEntityInterface $entity, arra ]); } else { - $links['comment-add'] += $entity->urlInfo()->toArray(); + $links['comment-add']['url'] = $entity->urlInfo(); } } } diff --git a/core/modules/comment/src/Form/CommentAdminOverview.php b/core/modules/comment/src/Form/CommentAdminOverview.php index c68f54b..4abff68 100644 --- a/core/modules/comment/src/Form/CommentAdminOverview.php +++ b/core/modules/comment/src/Form/CommentAdminOverview.php @@ -210,7 +210,8 @@ public function buildForm(array $form, FormStateInterface $form_state, $type = ' '#type' => 'link', '#title' => $commented_entity->label(), '#access' => $commented_entity->access('view'), - ) + $commented_entity->urlInfo()->toRenderArray(), + '#url' => $commented_entity->urlInfo(), + ), ), 'changed' => $this->dateFormatter->format($comment->getChangedTime(), 'short'), ); diff --git a/core/modules/config/src/Tests/ConfigEntityListTest.php b/core/modules/config/src/Tests/ConfigEntityListTest.php index b0818b9..c578ff2 100644 --- a/core/modules/config/src/Tests/ConfigEntityListTest.php +++ b/core/modules/config/src/Tests/ConfigEntityListTest.php @@ -48,21 +48,24 @@ function testList() { 'edit' => array ( 'title' => t('Edit'), 'weight' => 10, - ) + $entity->urlInfo()->toArray(), + 'url' => $entity->urlInfo(), + ), 'disable' => array( 'title' => t('Disable'), 'weight' => 40, - ) + $entity->urlInfo('disable')->toArray(), + 'url' => $entity->urlInfo('disable'), + ), 'delete' => array ( 'title' => t('Delete'), 'weight' => 100, - ) + $entity->urlInfo('delete-form')->toArray(), + 'url' => $entity->urlInfo('delete-form'), + ), ); $actual_operations = $controller->getOperations($entity); // Sort the operations to normalize link order. uasort($actual_operations, array('Drupal\Component\Utility\SortArray', 'sortByWeightElement')); - $this->assertIdentical($expected_operations, $actual_operations, 'The operations are identical.'); + $this->assertEqual($expected_operations, $actual_operations, 'The operations are identical.'); // Test buildHeader() method. $expected_items = array( @@ -71,7 +74,7 @@ function testList() { 'operations' => 'Operations', ); $actual_items = $controller->buildHeader(); - $this->assertIdentical($expected_items, $actual_items, 'Return value from buildHeader matches expected.'); + $this->assertEqual($expected_items, $actual_items, 'Return value from buildHeader matches expected.'); // Test buildRow() method. $build_operations = $controller->buildOperations($entity); @@ -83,7 +86,7 @@ function testList() { ), ); $actual_items = $controller->buildRow($entity); - $this->assertIdentical($expected_items, $actual_items, 'Return value from buildRow matches expected.'); + $this->assertEqual($expected_items, $actual_items, 'Return value from buildRow matches expected.'); // Test sorting. $storage = $controller->getStorage(); $entity = $storage->create(array( @@ -120,17 +123,19 @@ function testList() { 'edit' => array( 'title' => t('Edit'), 'weight' => 10, - ) + $entity->urlInfo()->toArray(), + 'url' => $entity->urlInfo(), + ), 'delete' => array( 'title' => t('Delete'), 'weight' => 100, - ) + $entity->urlInfo('delete-form')->toArray(), + 'url' => $entity->urlInfo('delete-form'), + ), ); $actual_operations = $controller->getOperations($entity); // Sort the operations to normalize link order. uasort($actual_operations, array('Drupal\Component\Utility\SortArray', 'sortByWeightElement')); - $this->assertIdentical($expected_operations, $actual_operations, 'The operations are identical.'); + $this->assertEqual($expected_operations, $actual_operations, 'The operations are identical.'); } /** diff --git a/core/modules/config_translation/config_translation.module b/core/modules/config_translation/config_translation.module index 956861a..306078f 100644 --- a/core/modules/config_translation/config_translation.module +++ b/core/modules/config_translation/config_translation.module @@ -173,7 +173,8 @@ function config_translation_entity_operation(EntityInterface $entity) { $operations['translate'] = array( 'title' => t('Translate'), 'weight' => 50, - ) + $entity->urlInfo('drupal:config-translation-overview')->toArray(); + 'url' => $entity->urlInfo('drupal:config-translation-overview'), + ); } return $operations; diff --git a/core/modules/config_translation/tests/src/Unit/ConfigEntityMapperTest.php b/core/modules/config_translation/tests/src/Unit/ConfigEntityMapperTest.php index 73cc7bb..2b1c67e 100644 --- a/core/modules/config_translation/tests/src/Unit/ConfigEntityMapperTest.php +++ b/core/modules/config_translation/tests/src/Unit/ConfigEntityMapperTest.php @@ -8,6 +8,7 @@ namespace Drupal\Tests\config_translation\Unit; use Drupal\config_translation\ConfigEntityMapper; +use Drupal\Core\Url; use Drupal\Tests\UnitTestCase; use Symfony\Component\Routing\Route; @@ -188,14 +189,11 @@ public function testGetOperations() { $expected = array( 'list' => array( 'title' => 'List', - 'route_name' => 'config_translation.entity_list', - 'route_parameters' => [ - 'mapper_id' => 'configurable_language', - ], + 'url' => Url::fromRoute('config_translation.entity_list', ['mapper_id' => 'configurable_language']), ), ); - $this->assertSame($expected, $result); + $this->assertEquals($expected, $result); } } diff --git a/core/modules/content_translation/content_translation.module b/core/modules/content_translation/content_translation.module index 49e4b67..4805ffb 100644 --- a/core/modules/content_translation/content_translation.module +++ b/core/modules/content_translation/content_translation.module @@ -169,7 +169,8 @@ 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')->toArray(); + 'url' => $entity->urlInfo('drupal:content-translation-overview'), + ); } } diff --git a/core/modules/content_translation/src/Controller/ContentTranslationController.php b/core/modules/content_translation/src/Controller/ContentTranslationController.php index b00a11f..999a509 100644 --- a/core/modules/content_translation/src/Controller/ContentTranslationController.php +++ b/core/modules/content_translation/src/Controller/ContentTranslationController.php @@ -136,10 +136,11 @@ public function overview(Request $request, $entity_type_id = NULL) { // the entity form, otherwise if we are not dealing with the original // language we point the link to the translation form. if ($entity->access('update')) { - $links['edit'] = $entity->urlInfo('edit-form')->toArray() + ['language' => $language]; + $links['edit']['url'] = $entity->urlInfo('edit-form'); + $links['edit']['language'] = $language; } elseif (!$is_original && $handler->getTranslationAccess($entity, 'update')->isAllowed()) { - $links['edit'] = $edit_url->toArray(); + $links['edit']['url'] = $edit_url; } if (isset($links['edit'])) { @@ -164,7 +165,8 @@ public function overview(Request $request, $entity_type_id = NULL) { if ($handler->getTranslationAccess($entity, 'delete')->isAllowed()) { $links['delete'] = array( 'title' => $this->t('Delete'), - ) + $delete_url->toArray(); + 'url' => $delete_url, + ); } } } @@ -177,7 +179,8 @@ public function overview(Request $request, $entity_type_id = NULL) { if ($translatable) { $links['add'] = array( 'title' => $this->t('Add'), - ) + $add_url->toArray(); + 'url' => $add_url, + ); } elseif ($field_ui) { $url = new Url('language.content_settings_page'); @@ -186,7 +189,8 @@ public function overview(Request $request, $entity_type_id = NULL) { // setting to enable translation on fields. $links['nofields'] = array( 'title' => $this->t('No translatable fields'), - ) + $url->toArray(); + 'url' => $url, + ); } } diff --git a/core/modules/field_ui/field_ui.module b/core/modules/field_ui/field_ui.module index e66da09..6b5f728 100644 --- a/core/modules/field_ui/field_ui.module +++ b/core/modules/field_ui/field_ui.module @@ -156,19 +156,22 @@ function field_ui_entity_operation(EntityInterface $entity) { $operations['manage-fields'] = array( 'title' => t('Manage fields'), 'weight' => 15, - ) + $entity->urlInfo('field_ui-fields')->toArray(); + 'url' => $entity->urlInfo('field_ui-fields'), + ); } if ($account->hasPermission('administer '. $bundle_of . ' form display')) { $operations['manage-form-display'] = array( 'title' => t('Manage form display'), 'weight' => 20, - ) + $entity->urlInfo('field_ui-form-display')->toArray(); + 'url' => $entity->urlInfo('field_ui-form-display'), + ); } if ($account->hasPermission('administer '. $bundle_of . ' display')) { $operations['manage-display'] = array( 'title' => t('Manage display'), 'weight' => 25, - ) + $entity->urlInfo('field_ui-display')->toArray(); + 'url' => $entity->urlInfo('field_ui-display'), + ); } } diff --git a/core/modules/field_ui/src/DisplayOverview.php b/core/modules/field_ui/src/DisplayOverview.php index 2bc07c1..1374494 100644 --- a/core/modules/field_ui/src/DisplayOverview.php +++ b/core/modules/field_ui/src/DisplayOverview.php @@ -17,6 +17,7 @@ use Drupal\Core\Field\FormatterInterface; use Drupal\Core\Field\PluginSettingsInterface; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Url; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -206,14 +207,10 @@ protected function getTableHeader() { * {@inheritdoc} */ protected function getOverviewRoute($mode) { - return array( - 'route_name' => 'field_ui.display_overview_view_mode_' . $this->entity_type, - 'route_parameters' => array( - $this->bundleEntityType => $this->bundle, - 'view_mode_name' => $mode, - ), - 'options' => array(), - ); + return Url::fromRoute('field_ui.display_overview_view_mode_' . $this->entity_type, [ + $this->bundleEntityType => $this->bundle, + 'view_mode_name' => $mode, + ]); } /** diff --git a/core/modules/field_ui/src/DisplayOverviewBase.php b/core/modules/field_ui/src/DisplayOverviewBase.php index 94db60a..05a20d9 100644 --- a/core/modules/field_ui/src/DisplayOverviewBase.php +++ b/core/modules/field_ui/src/DisplayOverviewBase.php @@ -595,8 +595,8 @@ public function submitForm(array &$form, FormStateInterface $form_state) { } $display_mode_label = $display_modes[$mode]['label']; - $route = $this->getOverviewRoute($mode); - drupal_set_message($this->t('The %display_mode mode now uses custom display settings. You might want to configure them.', array('%display_mode' => $display_mode_label, '@url' => $this->url($route['route_name'], $route['route_parameters'], $route['options'])))); + $url = $this->getOverviewRoute($mode); + drupal_set_message($this->t('The %display_mode mode now uses custom display settings. You might want to configure them.', array('%display_mode' => $display_mode_label, '@url' => $url->toString()))); } $statuses[$mode] = !empty($value); } @@ -872,14 +872,8 @@ protected function saveDisplayStatuses($display_statuses) { * @param string $mode * The form or view mode. * - * @return array - * An associative array with the following keys: - * - route_name: The name of the route. - * - route_parameters: (optional) An associative array of parameter names - * and values. - * - options: (optional) An associative array of additional options. See - * \Drupal\Core\Routing\UrlGeneratorInterface::generateFromRoute() for - * comprehensive documentation. + * @return \Drupal\Core\Url + * A Url object for the overview route. */ abstract protected function getOverviewRoute($mode); diff --git a/core/modules/field_ui/src/FieldConfigListBuilder.php b/core/modules/field_ui/src/FieldConfigListBuilder.php index f4f76b5..cae4250 100644 --- a/core/modules/field_ui/src/FieldConfigListBuilder.php +++ b/core/modules/field_ui/src/FieldConfigListBuilder.php @@ -66,7 +66,8 @@ public function getDefaultOperations(EntityInterface $entity) { 'title' => $this->t('Storage settings'), 'weight' => 20, 'attributes' => array('title' => $this->t('Edit storage settings.')), - ) + $entity->urlInfo('storage-edit-form')->toArray(); + 'url' => $entity->urlInfo('storage-edit-form'), + ); $operations['edit']['attributes']['title'] = $this->t('Edit field settings.'); $operations['delete']['attributes']['title'] = $this->t('Delete field.'); diff --git a/core/modules/field_ui/src/FormDisplayOverview.php b/core/modules/field_ui/src/FormDisplayOverview.php index aacd423..c317fd5 100644 --- a/core/modules/field_ui/src/FormDisplayOverview.php +++ b/core/modules/field_ui/src/FormDisplayOverview.php @@ -16,6 +16,7 @@ use Drupal\Core\Field\FieldTypePluginManager; use Drupal\Core\Field\PluginSettingsInterface; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Url; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -171,14 +172,10 @@ protected function getTableHeader() { * {@inheritdoc} */ protected function getOverviewRoute($mode) { - return array( - 'route_name' => 'field_ui.form_display_overview_form_mode_' . $this->entity_type, - 'route_parameters' => array( - $this->bundleEntityType => $this->bundle, - 'form_mode_name' => $mode, - ), - 'options' => array(), - ); + return Url::fromRoute('field_ui.form_display_overview_form_mode_' . $this->entity_type, [ + $this->bundleEntityType => $this->bundle, + 'form_mode_name' => $mode, + ]); } /** diff --git a/core/modules/forum/forum.module b/core/modules/forum/forum.module index 5f47d13..3719076 100644 --- a/core/modules/forum/forum.module +++ b/core/modules/forum/forum.module @@ -160,12 +160,7 @@ 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 Url::fromRoute('forum.page', ['taxonomy_term' => $forum->id()]); } /** diff --git a/core/modules/forum/src/Form/Overview.php b/core/modules/forum/src/Form/Overview.php index ceaa4d3..8469f55 100644 --- a/core/modules/forum/src/Form/Overview.php +++ b/core/modules/forum/src/Form/Overview.php @@ -68,20 +68,18 @@ public function buildForm(array $form, FormStateInterface $form_state) { $term = $form['terms'][$key]['#term']; $form['terms'][$key]['term']['#url'] = Url::fromRoute('forum.page', ['taxonomy_term' => $term->id()]); unset($form['terms'][$key]['operations']['#links']['delete']); + $route_parameters = $form['terms'][$key]['operations']['#links']['edit']['url']->getRouteParameters(); if (!empty($term->forum_container->value)) { $form['terms'][$key]['operations']['#links']['edit']['title'] = $this->t('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']); + $form['terms'][$key]['operations']['#links']['edit']['url'] = Url::fromRoute('forum.edit_container', $route_parameters); } else { $form['terms'][$key]['operations']['#links']['edit']['title'] = $this->t('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']); + $form['terms'][$key]['operations']['#links']['edit']['url'] = Url::fromRoute('forum.edit_forum', $route_parameters); } + // 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/help/src/Controller/HelpController.php b/core/modules/help/src/Controller/HelpController.php index 80ae8f4..2de0a53 100644 --- a/core/modules/help/src/Controller/HelpController.php +++ b/core/modules/help/src/Controller/HelpController.php @@ -126,7 +126,7 @@ public function helpPage($name) { if (!empty($admin_tasks)) { $links = array(); foreach ($admin_tasks as $task) { - $link = $task['url']->toArray(); + $link['url'] = $task['url']; $link['title'] = $task['title']; $links[] = $link; } diff --git a/core/modules/image/src/ImageStyleListBuilder.php b/core/modules/image/src/ImageStyleListBuilder.php index 73dfe6c..b0ad227 100644 --- a/core/modules/image/src/ImageStyleListBuilder.php +++ b/core/modules/image/src/ImageStyleListBuilder.php @@ -78,7 +78,8 @@ public function getDefaultOperations(EntityInterface $entity) { $flush = array( 'title' => t('Flush'), 'weight' => 200, - ) + $entity->urlInfo('flush-form')->toArray(); + 'url' => $entity->urlInfo('flush-form'), + ); return parent::getDefaultOperations($entity) + array( 'flush' => $flush, diff --git a/core/modules/language/tests/language_test/src/Controller/LanguageTestController.php b/core/modules/language/tests/language_test/src/Controller/LanguageTestController.php index a5cb033..6766d4a 100644 --- a/core/modules/language/tests/language_test/src/Controller/LanguageTestController.php +++ b/core/modules/language/tests/language_test/src/Controller/LanguageTestController.php @@ -9,6 +9,7 @@ use Drupal\Core\DependencyInjection\ContainerInjectionInterface; use Drupal\Core\Language\LanguageManagerInterface; +use Drupal\Core\Url; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\HttpKernelInterface; @@ -62,7 +63,7 @@ public function typeLinkActiveClass() { 'no_language' => array( '#type' => 'link', '#title' => t('Link to the current path with no langcode provided.'), - '#route_name' => '', + '#url' => Url::fromRoute(''), '#options' => array( 'attributes' => array( 'id' => 'no_lang_link', @@ -73,7 +74,7 @@ public function typeLinkActiveClass() { 'fr' => array( '#type' => 'link', '#title' => t('Link to a French version of the current path.'), - '#route_name' => '', + '#url' => Url::fromRoute(''), '#options' => array( 'language' => $languages['fr'], 'attributes' => array( @@ -85,7 +86,7 @@ public function typeLinkActiveClass() { 'en' => array( '#type' => 'link', '#title' => t('Link to an English version of the current path.'), - '#route_name' => '', + '#url' => Url::fromRoute(''), '#options' => array( 'language' => $languages['en'], 'attributes' => array( diff --git a/core/modules/menu_link_content/src/Plugin/Menu/MenuLinkContent.php b/core/modules/menu_link_content/src/Plugin/Menu/MenuLinkContent.php index ea47019..a3b525d 100644 --- a/core/modules/menu_link_content/src/Plugin/Menu/MenuLinkContent.php +++ b/core/modules/menu_link_content/src/Plugin/Menu/MenuLinkContent.php @@ -180,26 +180,21 @@ public function getDescription() { * {@inheritdoc} */ public function getDeleteRoute() { - return array( - 'route_name' => 'entity.menu_link_content.delete_form', - 'route_parameters' => array('menu_link_content' => $this->getEntity()->id()), - ); + return $this->getEntity()->urlInfo('delete-form'); } /** * {@inheritdoc} */ public function getEditRoute() { - return array( - 'route_name' => 'entity.menu_link_content.canonical', - 'route_parameters' => array('menu_link_content' => $this->getEntity()->id()), - ); + return $this->getEntity()->urlInfo(); } /** * {@inheritdoc} */ public function getTranslateRoute() { + return $this->getEntity()->urlInfo('drupal:content-translation-overview'); $entity_type = 'menu_link_content'; return array( 'route_name' => 'content_translation.translation_overview_' . $entity_type, diff --git a/core/modules/menu_ui/src/MenuForm.php b/core/modules/menu_ui/src/MenuForm.php index 720aa2b..f0f42b9 100644 --- a/core/modules/menu_ui/src/MenuForm.php +++ b/core/modules/menu_ui/src/MenuForm.php @@ -18,6 +18,7 @@ use Drupal\Core\Menu\MenuTreeParameters; use Drupal\Core\Render\Element; use Drupal\Core\Routing\UrlGeneratorTrait; +use Drupal\Core\Url; use Drupal\Core\Utility\LinkGeneratorInterface; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -306,23 +307,21 @@ protected function buildOverviewTreeForm($tree, $delta) { // Allow for a custom edit link per plugin. $edit_route = $link->getEditRoute(); if ($edit_route) { - $operations['edit'] += $edit_route; + $operations['edit']['url'] = $edit_route; // Bring the user back to the menu overview. $operations['edit']['query']['destination'] = $this->entity->url(); } else { // Fall back to the standard edit link. $operations['edit'] += array( - 'route_name' => 'menu_ui.link_edit', - 'route_parameters' => array('menu_link_plugin' => $link->getPluginId()), + 'url' => Url::fromRoute('menu_ui.link_edit', array('menu_link_plugin' => $link->getPluginId())), ); } // Links can either be reset or deleted, not both. if ($link->isResettable()) { $operations['reset'] = array( 'title' => $this->t('Reset'), - 'route_name' => 'menu_ui.link_reset', - 'route_parameters' => array('menu_link_plugin' => $link->getPluginId()), + 'url' => Url::fromRoute('menu_ui.link_reset', array('menu_link_plugin' => $link->getPluginId())), ); } elseif ($delete_link = $link->getDeleteRoute()) { @@ -333,7 +332,8 @@ protected function buildOverviewTreeForm($tree, $delta) { if ($link->isTranslatable()) { $operations['translate'] = array( 'title' => $this->t('Translate'), - ) + (array) $link->getTranslateRoute(); + 'url' => $link->getTranslateRoute(), + ); } $form[$id]['operations'] = array( '#type' => 'operations', diff --git a/core/modules/menu_ui/src/MenuListBuilder.php b/core/modules/menu_ui/src/MenuListBuilder.php index 4fdb298..7e987f1 100644 --- a/core/modules/menu_ui/src/MenuListBuilder.php +++ b/core/modules/menu_ui/src/MenuListBuilder.php @@ -54,7 +54,8 @@ public function getDefaultOperations(EntityInterface $entity) { $operations['add'] = array( 'title' => t('Add link'), 'weight' => 20, - ) + $entity->urlInfo('add-link-form')->toArray(); + 'url' => $entity->urlInfo('add-link-form'), + ); } if (isset($operations['delete'])) { $operations['delete']['title'] = t('Delete menu'); diff --git a/core/modules/responsive_image/src/ResponsiveImageMappingListBuilder.php b/core/modules/responsive_image/src/ResponsiveImageMappingListBuilder.php index b12fb61..6032b7c 100644 --- a/core/modules/responsive_image/src/ResponsiveImageMappingListBuilder.php +++ b/core/modules/responsive_image/src/ResponsiveImageMappingListBuilder.php @@ -41,7 +41,8 @@ public function getDefaultOperations(EntityInterface $entity) { $operations['duplicate'] = array( 'title' => t('Duplicate'), 'weight' => 15, - ) + $entity->urlInfo('duplicate-form')->toArray(); + 'url' => $entity->urlInfo('duplicate-form'), + ); return $operations; } diff --git a/core/modules/shortcut/shortcut.module b/core/modules/shortcut/shortcut.module index 8150bf2..2930fcb 100644 --- a/core/modules/shortcut/shortcut.module +++ b/core/modules/shortcut/shortcut.module @@ -366,7 +366,7 @@ function shortcut_toolbar() { $configure_link = array( '#type' => 'link', '#title' => t('Edit shortcuts'), - '#url' => Url::fromRoute('entity.shortcut_set.customize_form', ['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/shortcut/src/ShortcutSetListBuilder.php b/core/modules/shortcut/src/ShortcutSetListBuilder.php index 907f470..9de658d 100644 --- a/core/modules/shortcut/src/ShortcutSetListBuilder.php +++ b/core/modules/shortcut/src/ShortcutSetListBuilder.php @@ -37,7 +37,8 @@ public function getDefaultOperations(EntityInterface $entity) { $operations['list'] = array( 'title' => t('List links'), - ) + $entity->urlInfo('customize-form')->toArray(); + 'url' => $entity->urlInfo('customize-form'), + ); return $operations; } diff --git a/core/modules/simpletest/src/AssertContentTrait.php b/core/modules/simpletest/src/AssertContentTrait.php index 7c28b04..4e68c57 100644 --- a/core/modules/simpletest/src/AssertContentTrait.php +++ b/core/modules/simpletest/src/AssertContentTrait.php @@ -742,11 +742,6 @@ protected function assertNoTitle($title, $message = '', $group = 'Other') { */ protected function assertThemeOutput($callback, array $variables = array(), $expected = '', $message = '', $group = 'Other') { $output = \Drupal::theme()->render($callback, $variables); - $this->verbose('Variables:' . '
' . String::checkPlain(var_export($variables, TRUE)) . '
' - . '
' . 'Result:' . '
' . String::checkPlain(var_export($output, TRUE)) . '
' - . '
' . 'Expected:' . '
' . String::checkPlain(var_export($expected, TRUE)) . '
' - . '
' . $output - ); if (!$message) { $message = '%callback rendered correctly.'; } diff --git a/core/modules/system/src/Controller/DbUpdateController.php b/core/modules/system/src/Controller/DbUpdateController.php index 2a7992c..fdd9f71 100644 --- a/core/modules/system/src/Controller/DbUpdateController.php +++ b/core/modules/system/src/Controller/DbUpdateController.php @@ -348,7 +348,8 @@ protected function selection() { '#title' => $this->t('Apply pending updates'), '#attributes' => array('class' => array('button', 'button--primary')), '#weight' => 5, - ) + $url->toRenderArray(); + '#url' => $url, + ); } return $build; @@ -621,12 +622,12 @@ public static function batchFinished($success, $results, $operations) { protected function helpfulLinks() { $links['front'] = array( 'title' => $this->t('Front page'), - 'route_name' => '', + 'url' => Url::fromRoute(''), ); if ($this->account->hasPermission('access administration pages')) { $links['admin-pages'] = array( 'title' => $this->t('Administration pages'), - 'route_name' => 'system.admin', + 'url' => Url::fromRoute('system.admin'), ); } return $links; diff --git a/core/modules/system/src/Controller/SystemController.php b/core/modules/system/src/Controller/SystemController.php index 43ab34e..d634dd7 100644 --- a/core/modules/system/src/Controller/SystemController.php +++ b/core/modules/system/src/Controller/SystemController.php @@ -15,6 +15,7 @@ use Drupal\Core\Menu\MenuLinkTreeInterface; use Drupal\Core\Menu\MenuTreeParameters; use Drupal\Core\Theme\ThemeAccessCheck; +use Drupal\Core\Url; use Drupal\system\SystemManager; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -242,8 +243,7 @@ public function themesPage() { if ($this->themeAccess->checkAccess($theme->getName())) { $theme->operations[] = array( 'title' => $this->t('Settings'), - 'route_name' => 'system.theme_settings_theme', - 'route_parameters' => array('theme' => $theme->getName()), + 'url' => Url::fromRoute('system.theme_settings_theme', ['theme' => $theme->getName()]), 'attributes' => array('title' => $this->t('Settings for !theme theme', array('!theme' => $theme->info['name']))), ); } @@ -252,14 +252,14 @@ public function themesPage() { if ($theme->getName() != $admin_theme) { $theme->operations[] = array( 'title' => $this->t('Uninstall'), - 'route_name' => 'system.theme_uninstall', + 'url' => Url::fromRoute('system.theme_uninstall'), 'query' => $query, 'attributes' => array('title' => $this->t('Uninstall !theme theme', array('!theme' => $theme->info['name']))), ); } $theme->operations[] = array( 'title' => $this->t('Set as default'), - 'route_name' => 'system.theme_set_default', + 'url' => Url::fromRoute('system.theme_set_default'), 'query' => $query, 'attributes' => array('title' => $this->t('Set !theme as default theme', array('!theme' => $theme->info['name']))), ); @@ -269,13 +269,13 @@ public function themesPage() { else { $theme->operations[] = array( 'title' => $this->t('Install'), - 'route_name' => 'system.theme_install', + 'url' => Url::fromRoute('system.theme_install'), 'query' => $query, 'attributes' => array('title' => $this->t('Install !theme theme', array('!theme' => $theme->info['name']))), ); $theme->operations[] = array( 'title' => $this->t('Install and set as default'), - 'route_name' => 'system.theme_set_default', + 'url' => Url::fromRoute('system.theme_set_default'), 'query' => $query, 'attributes' => array('title' => $this->t('Install !theme as default theme', array('!theme' => $theme->info['name']))), ); diff --git a/core/modules/system/src/Tests/Common/RenderWebTest.php b/core/modules/system/src/Tests/Common/RenderWebTest.php index 5d7f36e..c2136dd 100644 --- a/core/modules/system/src/Tests/Common/RenderWebTest.php +++ b/core/modules/system/src/Tests/Common/RenderWebTest.php @@ -147,12 +147,7 @@ function testDrupalRenderFormElements() { * Tests that elements are rendered properly. */ protected function assertRenderedElement(array $element, $xpath, array $xpath_args = array()) { - $original_element = $element; $this->drupalSetContent(drupal_render($element)); - $this->verbose('
' .  String::checkPlain(var_export($original_element, TRUE)) . '
' - . '
' .  String::checkPlain(var_export($element, TRUE)) . '
' - . '
' . $this->drupalGetContent() - ); // @see \Drupal\simpletest\WebTestBase::xpath() $xpath = $this->buildXPathQuery($xpath, $xpath_args); diff --git a/core/modules/system/src/Tests/Common/UrlTest.php b/core/modules/system/src/Tests/Common/UrlTest.php index 01470a9..488c31b 100644 --- a/core/modules/system/src/Tests/Common/UrlTest.php +++ b/core/modules/system/src/Tests/Common/UrlTest.php @@ -118,7 +118,7 @@ function testLinkAttributes() { $type_link = array( '#type' => 'link', '#title' => $this->randomMachineName(), - '#route_name' => '', + '#url' => Url::fromRoute(''), '#options' => array( 'attributes' => array( 'class' => array($class_theme), diff --git a/core/modules/system/src/Tests/Theme/FunctionsTest.php b/core/modules/system/src/Tests/Theme/FunctionsTest.php index d04fa45..9eeeb47 100644 --- a/core/modules/system/src/Tests/Theme/FunctionsTest.php +++ b/core/modules/system/src/Tests/Theme/FunctionsTest.php @@ -10,6 +10,7 @@ use Drupal\Component\Serialization\Json; use Drupal\Component\Utility\String; use Drupal\Core\Session\UserSession; +use Drupal\Core\Url; use Drupal\simpletest\WebTestBase; /** @@ -193,17 +194,15 @@ function testLinks() { ), 'front page' => array( 'title' => 'Front page', - 'route_name' => '', + 'url' => Url::fromRoute(''), ), 'router-test' => array( 'title' => 'Test route', - 'route_name' => 'router_test.1', - 'route_parameters' => array(), + 'url' => Url::fromRoute('router_test.1'), ), 'query-test' => array( 'title' => 'Query test route', - 'route_name' => 'router_test.1', - 'route_parameters' => array(), + 'url' => Url::fromRoute('router_test.1'), 'query' => array( 'key' => 'value', ) @@ -287,7 +286,7 @@ function testDrupalPreRenderLinks() { '#links' => array( 'parent_link' => array( 'title' => 'Parent link original', - 'route_name' => 'router_test.1', + 'url' => Url::fromRoute('router_test.1'), ), ), 'first_child' => array( @@ -298,12 +297,12 @@ function testDrupalPreRenderLinks() { // one of the parent's links). 'parent_link' => array( 'title' => 'Parent link copy', - 'route_name' => 'router_test.6', + 'url' => Url::fromRoute('router_test.6'), ), // This should always be rendered. 'first_child_link' => array( 'title' => 'First child link', - 'route_name' => 'router_test.7', + 'url' => Url::fromRoute('router_test.7'), ), ), ), @@ -313,7 +312,7 @@ function testDrupalPreRenderLinks() { '#links' => array( 'second_child_link' => array( 'title' => 'Second child link', - 'route_name' => 'router_test.8', + 'url' => Url::fromRoute('router_test.8'), ), ), ), @@ -324,7 +323,7 @@ function testDrupalPreRenderLinks() { '#links' => array( 'third_child_link' => array( 'title' => 'Third child link', - 'route_name' => 'router_test.9', + 'url' => Url::fromRoute('router_test.9'), ), ), '#access' => FALSE, diff --git a/core/modules/system/system.api.php b/core/modules/system/system.api.php index 0c569c4..f27bc0e 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'), - 'url' => Url::fromRoute('node.add_page', array( + 'url' => Url::fromRoute('node.add_page'), + 'localized_options' => array( 'attributes' => array( 'title' => t('Add content'), ), - )), - 'localized_options' => , + ), ), ); @@ -426,7 +426,7 @@ function hook_menu_local_tasks(&$data, $route_name) { '#theme' => 'menu_local_task', '#link' => array( 'title' => t('Example tab'), - 'route_name' => 'node.add_page', + 'url' => Url::fromRoute('node.add_page'), 'localized_options' => array( 'attributes' => array( 'title' => t('Add content'), @@ -2277,7 +2277,7 @@ function hook_system_themes_page_alter(&$theme_groups) { // Add a foo link to each list of theme operations. $theme->operations[] = array( 'title' => t('Foo'), - 'route_name' => 'system.themes_page', + 'url' => Url::fromRoute('system.themes_page'), 'query' => array('theme' => $theme->getName()) ); } diff --git a/core/modules/system/tests/modules/common_test/src/Controller/CommonTestController.php b/core/modules/system/tests/modules/common_test/src/Controller/CommonTestController.php index d99a896..cf82dba 100644 --- a/core/modules/system/tests/modules/common_test/src/Controller/CommonTestController.php +++ b/core/modules/system/tests/modules/common_test/src/Controller/CommonTestController.php @@ -26,7 +26,7 @@ public function typeLinkActiveClass() { 'no_query' => array( '#type' => 'link', '#title' => t('Link with no query string'), - '#route_name' => '', + '#url' => Url::fromRoute(''), '#options' => array( 'set_active_class' => TRUE, ), @@ -34,7 +34,7 @@ public function typeLinkActiveClass() { 'with_query' => array( '#type' => 'link', '#title' => t('Link with a query string'), - '#route_name' => '', + '#url' => Url::fromRoute(''), '#options' => array( 'query' => array( 'foo' => 'bar', @@ -46,7 +46,7 @@ public function typeLinkActiveClass() { 'with_query_reversed' => array( '#type' => 'link', '#title' => t('Link with the same query string in reverse order'), - '#route_name' => '', + '#url' => Url::fromRoute(''), '#options' => array( 'query' => array( 'one' => 'two', diff --git a/core/modules/taxonomy/src/Form/OverviewTerms.php b/core/modules/taxonomy/src/Form/OverviewTerms.php index ffe0ea1..65ed68a 100644 --- a/core/modules/taxonomy/src/Form/OverviewTerms.php +++ b/core/modules/taxonomy/src/Form/OverviewTerms.php @@ -269,17 +269,20 @@ public function buildForm(array $form, FormStateInterface $form_state, Vocabular 'edit' => array( 'title' => $this->t('Edit'), 'query' => $destination, - ) + $term->urlInfo('edit-form')->toArray(), + 'url' => $term->urlInfo('edit-form'), + ), 'delete' => array( 'title' => $this->t('Delete'), 'query' => $destination, - ) + $term->urlInfo('delete-form')->toArray(), + 'url' => $term->urlInfo('delete-form'), + ), ); if ($this->moduleHandler->moduleExists('content_translation') && content_translation_translate_access($term)->isAllowed()) { $operations['translate'] = array( 'title' => $this->t('Translate'), 'query' => $destination, - ) + $term->urlInfo('drupal:content-translation-overview')->toArray(); + 'url' => $term->urlInfo('drupal:content-translation-overview'), + ); } $form['terms'][$key]['operations'] = array( '#type' => 'operations', diff --git a/core/modules/taxonomy/src/VocabularyListBuilder.php b/core/modules/taxonomy/src/VocabularyListBuilder.php index a5a02fc..bb385df 100644 --- a/core/modules/taxonomy/src/VocabularyListBuilder.php +++ b/core/modules/taxonomy/src/VocabularyListBuilder.php @@ -43,11 +43,13 @@ public function getDefaultOperations(EntityInterface $entity) { $operations['list'] = array( 'title' => t('List terms'), 'weight' => 0, - ) + $entity->urlInfo('overview-form')->toArray(); + 'url' => $entity->urlInfo('overview-form'), + ); $operations['add'] = array( 'title' => t('Add terms'), 'weight' => 10, - ) + $entity->urlInfo('add-form')->toArray(); + 'url' => $entity->urlInfo('add-form'), + ); unset($operations['delete']); return $operations; diff --git a/core/modules/user/src/RoleListBuilder.php b/core/modules/user/src/RoleListBuilder.php index 8e7feec..4e0dd73 100644 --- a/core/modules/user/src/RoleListBuilder.php +++ b/core/modules/user/src/RoleListBuilder.php @@ -51,7 +51,8 @@ public function getDefaultOperations(EntityInterface $entity) { $operations['permissions'] = array( 'title' => t('Edit permissions'), 'weight' => 20, - ) + $entity->urlInfo('edit-permissions-form')->toArray(); + 'url' => $entity->urlInfo('edit-permissions-form'), + ); } return $operations; } diff --git a/core/modules/views/views.theme.inc b/core/modules/views/views.theme.inc index 02f0175..f089f56 100644 --- a/core/modules/views/views.theme.inc +++ b/core/modules/views/views.theme.inc @@ -1049,7 +1049,7 @@ function template_preprocess_views_mini_pager(&$variables) { $li_previous = array( '#type' => 'link', '#title' => $tags[1], - '#route_name' => '', + '#url' => Url::fromRoute(''), '#options' => array( 'query' => pager_query_add_page($parameters, $element, $pager_page_array[$element] - 1), 'attributes' => array( @@ -1072,7 +1072,7 @@ function template_preprocess_views_mini_pager(&$variables) { $li_next = array( '#type' => 'link', '#title' => $tags[3], - '#route_name' => '', + '#url' => Url::fromRoute(''), '#options' => array( 'query' => pager_query_add_page($parameters, $element, $pager_page_array[$element] + 1), 'attributes' => array( diff --git a/core/modules/views_ui/src/ViewEditForm.php b/core/modules/views_ui/src/ViewEditForm.php index 2ca0dca..3b82ebe 100644 --- a/core/modules/views_ui/src/ViewEditForm.php +++ b/core/modules/views_ui/src/ViewEditForm.php @@ -705,7 +705,8 @@ public function renderDisplayTop(ViewUI $view) { ), 'duplicate' => array( 'title' => $this->t('Duplicate view'), - ) + $view->urlInfo('duplicate-form')->toArray(), + 'url' => $view->urlInfo('duplicate-form'), + ), 'reorder' => array( 'title' => $this->t('Reorder displays'), 'url' => Url::fromRoute('views_ui.form_reorder_displays', ['js' => 'nojs', 'view' => $view->id(), 'display_id' => $display_id]), @@ -717,7 +718,8 @@ public function renderDisplayTop(ViewUI $view) { if ($view->access('delete')) { $element['extra_actions']['#links']['delete'] = array( 'title' => $this->t('Delete view'), - ) + $view->urlInfo('delete-form')->toArray(); + 'url' => $view->urlInfo('delete-form'), + ); } // Let other modules add additional links here. diff --git a/core/modules/views_ui/src/ViewFormBase.php b/core/modules/views_ui/src/ViewFormBase.php index 9544040..39f1a0d 100644 --- a/core/modules/views_ui/src/ViewFormBase.php +++ b/core/modules/views_ui/src/ViewFormBase.php @@ -122,9 +122,9 @@ public function getDisplayTabs(ViewUI $view) { '#link' => array( 'title' => $this->getDisplayLabel($view, $id), 'localized_options' => array(), - ) + $view->urlInfo('edit-display-form')->toArray(), + 'url' => $view->urlInfo('edit-display-form')->setRouteParameter('display_id', $id), + ), ); - $tabs[$id]['#link']['route_parameters']['display_id'] = $id; if (!empty($display['deleted'])) { $tabs[$id]['#link']['localized_options']['attributes']['class'][] = 'views-display-deleted-link'; } diff --git a/core/modules/views_ui/src/ViewListBuilder.php b/core/modules/views_ui/src/ViewListBuilder.php index 9d12e5a..c8dcbe1 100644 --- a/core/modules/views_ui/src/ViewListBuilder.php +++ b/core/modules/views_ui/src/ViewListBuilder.php @@ -149,15 +149,14 @@ public function getDefaultOperations(EntityInterface $entity) { $operations['duplicate'] = array( 'title' => $this->t('Duplicate'), 'weight' => 15, - ) + $entity->urlInfo('duplicate-form')->toArray(); + 'url' => $entity->urlInfo('duplicate-form'), + ); } // Add AJAX functionality to enable/disable operations. foreach (array('enable', 'disable') as $op) { if (isset($operations[$op])) { - $operations[$op]['route_name'] = "entity.view.{$op}"; - $operations[$op]['route_parameters'] = array('view' => $entity->id()); - + $operations[$op]['url'] = $entity->urlInfo($op); // Enable and disable operations should use AJAX. $operations[$op]['attributes']['class'][] = 'use-ajax'; } diff --git a/core/modules/views_ui/views_ui.module b/core/modules/views_ui/views_ui.module index ca61352..b6e92b6 100644 --- a/core/modules/views_ui/views_ui.module +++ b/core/modules/views_ui/views_ui.module @@ -253,8 +253,8 @@ function views_ui_contextual_links_view_alter(&$element, $items) { // screen. elseif (!empty($element['#links']['entityviewedit-form'])) { $display_id = $items['entity.view.edit_form']['metadata']['display_id']; - $element['#links']['entityviewedit-form']['route_parameters']['display_id'] = $display_id; - $element['#links']['entityviewedit-form']['route_name'] = 'entity.view.edit_display_form'; + $route_parameters = $element['#links']['entityviewedit-form']['url']->getRouteParameters() + ['display_id' => $display_id]; + $element['#links']['entityviewedit-form']['url'] = Url::fromRoute('entity.view.edit_display_form', $route_parameters); } } diff --git a/core/tests/Drupal/Tests/Core/Form/ConfirmFormHelperTest.php b/core/tests/Drupal/Tests/Core/Form/ConfirmFormHelperTest.php index 842304c..b80567f 100644 --- a/core/tests/Drupal/Tests/Core/Form/ConfirmFormHelperTest.php +++ b/core/tests/Drupal/Tests/Core/Form/ConfirmFormHelperTest.php @@ -56,16 +56,7 @@ public function testCancelLinkRoute() { * Tests a cancel link route with parameters. */ public function testCancelLinkRouteWithParams() { - $cancel_route = array( - 'route_name' => 'foo_bar.baz', - 'route_parameters' => array( - 'baz' => 'banana', - ), - 'options' => array( - 'absolute' => TRUE, - ), - ); - $expected = Url::fromRoute($cancel_route['route_name'], $cancel_route['route_parameters'], $cancel_route['options']); + $expected = Url::fromRoute('foo_bar.baz', ['baz' => 'banana'], ['absolute' => TRUE]); $form = $this->getMock('Drupal\Core\Form\ConfirmFormInterface'); $form->expects($this->any()) ->method('getCancelUrl') diff --git a/core/tests/Drupal/Tests/Core/Menu/LocalActionManagerTest.php b/core/tests/Drupal/Tests/Core/Menu/LocalActionManagerTest.php index 1942fc3..219ef03 100644 --- a/core/tests/Drupal/Tests/Core/Menu/LocalActionManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Menu/LocalActionManagerTest.php @@ -16,6 +16,7 @@ use Drupal\Core\Menu\LocalActionManager; use Drupal\Core\Routing\RouteProviderInterface; use Drupal\Core\Session\AccountInterface; +use Drupal\Core\Url; use Drupal\Tests\UnitTestCase; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RequestStack; @@ -196,8 +197,7 @@ public function getActionsForRouteProvider() { '#theme' => 'menu_local_action', '#link' => array( 'title' => 'Plugin ID 1', - 'route_name' => 'test_route_2', - 'route_parameters' => array(), + 'url' => Url::fromRoute('test_route_2'), 'localized_options' => '', ), '#access' => FALSE, @@ -231,8 +231,7 @@ public function getActionsForRouteProvider() { '#theme' => 'menu_local_action', '#link' => array( 'title' => 'Plugin ID 1', - 'route_name' => 'test_route_2', - 'route_parameters' => array(), + 'url' => Url::fromRoute('test_route_2'), 'localized_options' => '', ), '#access' => FALSE, @@ -267,8 +266,7 @@ public function getActionsForRouteProvider() { '#theme' => 'menu_local_action', '#link' => array( 'title' => 'Plugin ID 1', - 'route_name' => 'test_route_2', - 'route_parameters' => array(), + 'url' => Url::fromRoute('test_route_2'), 'localized_options' => '', ), '#access' => FALSE, @@ -278,8 +276,7 @@ public function getActionsForRouteProvider() { '#theme' => 'menu_local_action', '#link' => array( 'title' => 'Plugin ID 2', - 'route_name' => 'test_route_3', - 'route_parameters' => array(), + 'url' => Url::fromRoute('test_route_3'), 'localized_options' => '', ), '#access' => FALSE, @@ -316,8 +313,7 @@ public function getActionsForRouteProvider() { '#theme' => 'menu_local_action', '#link' => array( 'title' => 'Plugin ID 1', - 'route_name' => 'test_route_2', - 'route_parameters' => array('test1'), + 'url' => Url::fromRoute('test_route_2', ['test1']), 'localized_options' => '', ), '#access' => FALSE, @@ -327,8 +323,7 @@ public function getActionsForRouteProvider() { '#theme' => 'menu_local_action', '#link' => array( 'title' => 'Plugin ID 2', - 'route_name' => 'test_route_2', - 'route_parameters' => array('test2'), + 'url' => Url::fromRoute('test_route_2', ['test2']), 'localized_options' => '', ), '#access' => FALSE, diff --git a/core/tests/Drupal/Tests/Core/UnroutedUrlTest.php b/core/tests/Drupal/Tests/Core/UnroutedUrlTest.php index 9d6ea00..fcc1613 100644 --- a/core/tests/Drupal/Tests/Core/UnroutedUrlTest.php +++ b/core/tests/Drupal/Tests/Core/UnroutedUrlTest.php @@ -146,17 +146,13 @@ public function testToString(array $urls) { * @covers ::toArray */ public function testToArray(array $urls) { - $expected = array( - 'path' => $this->unroutedExternal, - 'options' => array('external' => TRUE), - ); - $this->assertSame($expected, $urls[0]->toArray()); + $expected = Url::fromUri($this->unroutedExternal, array('external' => TRUE)); + $expected->setUnroutedUrlAssembler(\Drupal::service('unrouted_url_assembler')); + $this->assertEquals($expected, $urls[0]); - $expected = array( - 'path' => $this->unroutedInternal, - 'options' => array(), - ); - $this->assertSame($expected, $urls[1]->toArray()); + $expected = Url::fromUri($this->unroutedInternal, array()); + $expected->setUnroutedUrlAssembler(\Drupal::service('unrouted_url_assembler')); + $this->assertEquals($expected, $urls[1]); } /** diff --git a/core/tests/Drupal/Tests/Core/UrlTest.php b/core/tests/Drupal/Tests/Core/UrlTest.php index 75c4768..404702e 100644 --- a/core/tests/Drupal/Tests/Core/UrlTest.php +++ b/core/tests/Drupal/Tests/Core/UrlTest.php @@ -102,7 +102,8 @@ public function testUrlFromRequest() { foreach ($this->map as $index => $values) { $path = array_pop($values); $url = Url::createFromRequest(Request::create("$path")); - $this->assertSame($values, array_values($url->toArray())); + $expected = Url::fromRoute($values[0], $values[1], $values[2]); + $this->assertEquals($expected, $url); $urls[$index] = $url; } return $urls; @@ -245,12 +246,9 @@ public function testToString($urls) { */ public function testToArray($urls) { foreach ($urls as $index => $url) { - $expected = array( - 'route_name' => $this->map[$index][0], - 'route_parameters' => $this->map[$index][1], - 'options' => $this->map[$index][2], - ); - $this->assertSame($expected, $url->toArray()); + $expected = Url::fromRoute($this->map[$index][0], $this->map[$index][1], $this->map[$index][2]); + $expected->setUrlGenerator(\Drupal::urlGenerator()); + $this->assertEquals($expected, $url); } }