diff --git a/core/includes/common.inc b/core/includes/common.inc index 349449a..092bbb0 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -21,6 +21,7 @@ use Drupal\Core\Cache\Cache; use Drupal\Core\Language\Language; use Drupal\Core\Site\Settings; +use Drupal\Core\Url; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Request; use Drupal\Core\PhpStorage\PhpStorageFactory; @@ -2943,7 +2944,8 @@ function drupal_pre_render_link($element) { if (isset($element['#route_name'])) { $element['#route_parameters'] = empty($element['#route_parameters']) ? array() : $element['#route_parameters']; - $element['#markup'] = \Drupal::linkGenerator()->generate($element['#title'], $element['#route_name'], $element['#route_parameters'], $element['#options']); + $url = new Url($element['#route_name'], $element['#route_parameters'], $element['#options']); + $element['#markup'] = \Drupal::l($element['#title'], $url); } else { $element['#markup'] = l($element['#title'], $element['#href'], $element['#options']); diff --git a/core/includes/menu.inc b/core/includes/menu.inc index 46de223..fa12b48 100644 --- a/core/includes/menu.inc +++ b/core/includes/menu.inc @@ -10,6 +10,7 @@ use Drupal\Core\Language\Language; use Drupal\Core\Render\Element; use Drupal\Core\Template\Attribute; +use Drupal\Core\Url; use Symfony\Cmf\Component\Routing\RouteObjectInterface; /** @@ -301,7 +302,8 @@ function theme_menu_local_task($variables) { $a_tag = l($link_text, $link['href'], $link['localized_options']); } else { - $a_tag = \Drupal::l($link_text, $link['route_name'], $link['route_parameters'], $link['localized_options']); + $url = new Url($link['route_name'], $link['route_parameters'], $link['localized_options']); + $a_tag = \Drupal::l($link_text, $url); } return '' . $a_tag . ''; @@ -334,7 +336,8 @@ function theme_menu_local_action($variables) { // routes. // @todo Figure out how to support local actions without a href properly. if ($link['href'] === '' && !empty($link['route_name'])) { - $output .= Drupal::l($link['title'], $link['route_name'], $link['route_parameters'], $link['localized_options']); + $url = new Url($link['route_name'], $link['route_parameters'], $link['localized_options']); + $output .= \Drupal::l($link['title'], $url); } else { $output .= l($link['title'], $link['href'], $link['localized_options']); diff --git a/core/lib/Drupal.php b/core/lib/Drupal.php index 83fe15f..03c9f33 100644 --- a/core/lib/Drupal.php +++ b/core/lib/Drupal.php @@ -5,6 +5,7 @@ * Contains Drupal. */ +use Drupal\Core\Url; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -510,32 +511,8 @@ public static function linkGenerator() { * * @param string|array $text * The link text for the anchor tag as a translated string or render array. - * @param string $route_name - * The name of the route to use to generate the link. - * @param array $parameters - * (optional) Any parameters needed to render the route path pattern. - * @param array $options - * (optional) An associative array of additional options. Defaults to an - * empty array. It may contain the following elements: - * - 'query': An array of query key/value-pairs (without any URL-encoding) to - * append to the URL. - * - absolute: Whether to force the output to be an absolute link (beginning - * with http:). Useful for links that will be displayed outside the site, - * such as in an RSS feed. Defaults to FALSE. - * - attributes: An associative array of HTML attributes to apply to the - * anchor tag. If element 'class' is included, it must be an array; 'title' - * must be a string; other elements are more flexible, as they just need - * to work as an argument for the constructor of the class - * Drupal\Core\Template\Attribute($options['attributes']). - * - html: Whether $text is HTML or just plain-text. For - * example, to make an image tag into a link, this must be set to TRUE, or - * you will see the escaped HTML image tag. $text is not sanitized if - * 'html' is TRUE. The calling function must ensure that $text is already - * safe. Defaults to FALSE. - * - language: An optional language object. If the path being linked to is - * internal to the site, $options['language'] is used to determine whether - * the link is "active", or pointing to the current page (the language as - * well as the path must match). + * @param \Drupal\Core\Url $url + * The URL object used for the link. * * @return string * An HTML string containing a link to the given route and parameters. @@ -548,11 +525,10 @@ public static function linkGenerator() { * Thrown when a parameter value for a placeholder is not correct because it * does not match the requirement. * - * @see \Drupal\Core\Routing\UrlGeneratorInterface::generateFromRoute() - * @see \Drupal\Core\Utility\LinkGeneratorInterface::generate() + * @see \Drupal\Core\Utility\LinkGeneratorInterface::generateFromUrl() */ - public static function l($text, $route_name, array $parameters = array(), array $options = array()) { - return static::$container->get('link_generator')->generate($text, $route_name, $parameters, $options); + public static function l($text, Url $url) { + return static::linkGenerator()->generateFromUrl($text, $url); } /** diff --git a/core/modules/block/custom_block/custom_block.pages.inc b/core/modules/block/custom_block/custom_block.pages.inc index f24e16b..a5af184 100644 --- a/core/modules/block/custom_block/custom_block.pages.inc +++ b/core/modules/block/custom_block/custom_block.pages.inc @@ -6,6 +6,7 @@ */ use Drupal\Component\Utility\Xss; +use Drupal\Core\Url; use Drupal\custom_block\Entity\CustomBlockType; use Drupal\custom_block\Entity\CustomBlock; use Symfony\Component\HttpFoundation\RedirectResponse; @@ -26,7 +27,7 @@ function template_preprocess_custom_block_add_list(&$variables) { $query = \Drupal::request()->query->all(); foreach ($variables['content'] as $type) { $variables['types'][$type->id()] = array( - 'link' => \Drupal::l($type->label(), 'custom_block.add_form', array('custom_block_type' => $type->id()), array('query' => $query)), + 'link' => \Drupal::l($type->label(), new Url('custom_block.add_form', array('custom_block_type' => $type->id()), array('query' => $query))), 'description' => Xss::filterAdmin($type->description), 'title' => $type->label(), 'localized_options' => array( diff --git a/core/modules/block/custom_block/src/CustomBlockTypeForm.php b/core/modules/block/custom_block/src/CustomBlockTypeForm.php index 61567f8..c0efe90 100644 --- a/core/modules/block/custom_block/src/CustomBlockTypeForm.php +++ b/core/modules/block/custom_block/src/CustomBlockTypeForm.php @@ -91,7 +91,7 @@ public function save(array $form, array &$form_state) { $block_type = $this->entity; $status = $block_type->save(); - $edit_link = \Drupal::linkGenerator()->generateFromUrl($this->t('Edit'), $this->entity->urlInfo()); + $edit_link = \Drupal::l($this->t('Edit'), $this->entity->urlInfo()); if ($status == SAVED_UPDATED) { drupal_set_message(t('Custom block type %label has been updated.', array('%label' => $block_type->label()))); watchdog('custom_block', 'Custom block type %label has been updated.', array('%label' => $block_type->label()), WATCHDOG_NOTICE, $edit_link); diff --git a/core/modules/block/custom_block/src/CustomBlockTypeListBuilder.php b/core/modules/block/custom_block/src/CustomBlockTypeListBuilder.php index 723ea71..1646de6 100644 --- a/core/modules/block/custom_block/src/CustomBlockTypeListBuilder.php +++ b/core/modules/block/custom_block/src/CustomBlockTypeListBuilder.php @@ -44,7 +44,7 @@ public function buildHeader() { * {@inheritdoc} */ public function buildRow(EntityInterface $entity) { - $row['type'] = \Drupal::linkGenerator()->generateFromUrl($entity->label(), $entity->urlInfo()); + $row['type'] = \Drupal::l($entity->label(), $entity->urlInfo()); $row['description'] = Xss::filterAdmin($entity->description); return $row + parent::buildRow($entity); } diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index b09bfa8..5f56206 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -1384,9 +1384,9 @@ function template_preprocess_comment(&$variables) { $attributes = $uri->getOption('attributes') ?: array(); $attributes += array('class' => array('permalink'), 'rel' => 'bookmark'); $uri->setOption('attributes', $attributes); - $variables['title'] = \Drupal::linkGenerator()->generateFromUrl($comment->getSubject(), $uri); + $variables['title'] = \Drupal::l($comment->getSubject(), $uri); - $variables['permalink'] = \Drupal::linkGenerator()->generateFromUrl(t('Permalink'), $comment->permalink()); + $variables['permalink'] = \Drupal::l(t('Permalink'), $comment->permalink()); } $variables['submitted'] = t('Submitted by !username on !datetime', array('!username' => $variables['author'], '!datetime' => $variables['created'])); @@ -1413,8 +1413,8 @@ function template_preprocess_comment(&$variables) { $attributes = $permalink_uri_parent->getOption('attributes') ?: array(); $attributes += array('class' => array('permalink'), 'rel' => 'bookmark'); $permalink_uri_parent->setOption('attributes', $attributes); - $variables['parent_title'] = \Drupal::linkGenerator()->generateFromUrl($comment_parent->getSubject(), $permalink_uri_parent); - $variables['parent_permalink'] = \Drupal::linkGenerator()->generateFromUrl(t('Parent permalink'), $permalink_uri_parent); + $variables['parent_title'] = \Drupal::l($comment_parent->getSubject(), $permalink_uri_parent); + $variables['parent_permalink'] = \Drupal::l(t('Parent permalink'), $permalink_uri_parent); $variables['parent'] = t('In reply to !parent_title by !parent_username', array('!parent_username' => $variables['parent_author'], '!parent_title' => $variables['parent_title'])); } diff --git a/core/modules/comment/src/CommentBreadcrumbBuilder.php b/core/modules/comment/src/CommentBreadcrumbBuilder.php index 9626963..5e54729 100644 --- a/core/modules/comment/src/CommentBreadcrumbBuilder.php +++ b/core/modules/comment/src/CommentBreadcrumbBuilder.php @@ -53,7 +53,7 @@ public function build(array $attributes) { $entity = $this->entityManager ->getStorage($attributes['entity_type']) ->load($attributes['entity_id']); - $breadcrumb[] = \Drupal::linkGenerator()->generateFromUrl($entity->label(), $entity->urlInfo()); + $breadcrumb[] = \Drupal::l($entity->label(), $entity->urlInfo()); return $breadcrumb; } diff --git a/core/modules/comment/src/Controller/AdminController.php b/core/modules/comment/src/Controller/AdminController.php index 9c8d43c..77769f0 100644 --- a/core/modules/comment/src/Controller/AdminController.php +++ b/core/modules/comment/src/Controller/AdminController.php @@ -125,7 +125,7 @@ public function overviewBundles() { if (isset($entity_bundles[$entity_type][$bundle])) { // Add the current instance. if ($field_ui_enabled && $route_info = FieldUI::getOverviewRouteInfo($entity_type, $bundle)) { - $row['data']['usage']['data']['#items'][] = \Drupal::linkGenerator()->generateFromUrl($entity_bundles[$entity_type][$bundle]['label'], $route_info); + $row['data']['usage']['data']['#items'][] = \Drupal::l($entity_bundles[$entity_type][$bundle]['label'], $route_info); } else { $row['data']['usage']['data']['#items'][] = $entity_bundles[$entity_type][$bundle]['label']; diff --git a/core/modules/contact/src/CategoryForm.php b/core/modules/contact/src/CategoryForm.php index 14c893d..bc62258 100644 --- a/core/modules/contact/src/CategoryForm.php +++ b/core/modules/contact/src/CategoryForm.php @@ -99,7 +99,7 @@ public function save(array $form, array &$form_state) { $category = $this->entity; $status = $category->save(); - $edit_link = \Drupal::linkGenerator()->generateFromUrl($this->t('Edit'), $this->entity->urlInfo()); + $edit_link = \Drupal::l($this->t('Edit'), $this->entity->urlInfo()); if ($status == SAVED_UPDATED) { drupal_set_message(t('Category %label has been updated.', array('%label' => $category->label()))); diff --git a/core/modules/field_ui/src/FieldConfigListBuilder.php b/core/modules/field_ui/src/FieldConfigListBuilder.php index 0da1bf9..fafd9e6 100644 --- a/core/modules/field_ui/src/FieldConfigListBuilder.php +++ b/core/modules/field_ui/src/FieldConfigListBuilder.php @@ -111,7 +111,7 @@ public function buildRow(EntityInterface $field) { $usage = array(); foreach ($field->getBundles() as $bundle) { if ($route_info = FieldUI::getOverviewRouteInfo($field->entity_type, $bundle)) { - $usage[] = \Drupal::linkGenerator()->generateFromUrl($this->bundles[$field->entity_type][$bundle]['label'], $route_info); + $usage[] = \Drupal::l($this->bundles[$field->entity_type][$bundle]['label'], $route_info); } else { $usage[] = $this->bundles[$field->entity_type][$bundle]['label']; diff --git a/core/modules/link/link.module b/core/modules/link/link.module index a791a15..9d84d9c 100644 --- a/core/modules/link/link.module +++ b/core/modules/link/link.module @@ -66,7 +66,7 @@ function template_preprocess_link_formatter_link_separate(&$variables) { } if (!$variables['url']->isExternal()) { - $variables['link'] = \Drupal::linkGenerator()->generateFromUrl($variables['url_title'], $variables['url']); + $variables['link'] = \Drupal::l($variables['url_title'], $variables['url']); } else { $variables['link'] = l($variables['url_title'], $variables['url']->getPath(), $variables['url']->getOptions()); diff --git a/core/modules/menu_link/menu_link.module b/core/modules/menu_link/menu_link.module index ac3c408..b13b3c8 100644 --- a/core/modules/menu_link/menu_link.module +++ b/core/modules/menu_link/menu_link.module @@ -221,7 +221,7 @@ function menu_link_system_breadcrumb_alter(array &$breadcrumb, array $attributes if (($menu_link instanceof MenuLinkInterface) && !$menu_link->isNew()) { // Add a link to the menu admin screen. $menu = entity_load('menu', $menu_link->menu_name); - $breadcrumb[] = Drupal::l($menu->label(), 'menu_ui.menu_edit', array('menu' => $menu->id)); + $breadcrumb[] = \Drupal::l($menu->label(), new Url('menu_ui.menu_edit', array('menu' => $menu->id))); } } } diff --git a/core/modules/menu_ui/src/MenuForm.php b/core/modules/menu_ui/src/MenuForm.php index a1c422d..0408bc1 100644 --- a/core/modules/menu_ui/src/MenuForm.php +++ b/core/modules/menu_ui/src/MenuForm.php @@ -217,7 +217,7 @@ public function save(array $form, array &$form_state) { $status = $menu->save(); - $edit_link = \Drupal::linkGenerator()->generateFromUrl($this->t('Edit'), $this->entity->urlInfo()); + $edit_link = \Drupal::l($this->t('Edit'), $this->entity->urlInfo()); if ($status == SAVED_UPDATED) { drupal_set_message(t('Menu %label has been updated.', array('%label' => $menu->label()))); watchdog('menu', 'Menu %label has been updated.', array('%label' => $menu->label()), WATCHDOG_NOTICE, $edit_link); diff --git a/core/modules/system/system.api.php b/core/modules/system/system.api.php index c7c8a49..7de7b67 100644 --- a/core/modules/system/system.api.php +++ b/core/modules/system/system.api.php @@ -905,7 +905,7 @@ function hook_module_implements_alter(&$implementations, $hook) { */ function hook_system_breadcrumb_alter(array &$breadcrumb, array $attributes, array $context) { // Add an item to the end of the breadcrumb. - $breadcrumb[] = Drupal::l(t('Text'), 'example_route_name'); + $breadcrumb[] = \Drupal::l(t('Text'), new \Drupal\Core\Url('example_route_name')); } /** diff --git a/core/modules/taxonomy/src/VocabularyForm.php b/core/modules/taxonomy/src/VocabularyForm.php index 341bcbe..b07d61a 100644 --- a/core/modules/taxonomy/src/VocabularyForm.php +++ b/core/modules/taxonomy/src/VocabularyForm.php @@ -137,7 +137,7 @@ public function save(array $form, array &$form_state) { $vocabulary->name = trim($vocabulary->name); $status = $vocabulary->save(); - $edit_link = \Drupal::linkGenerator()->generateFromUrl($this->t('Edit'), $this->entity->urlInfo()); + $edit_link = \Drupal::l($this->t('Edit'), $this->entity->urlInfo()); switch ($status) { case SAVED_NEW: drupal_set_message($this->t('Created new vocabulary %name.', array('%name' => $vocabulary->name))); diff --git a/core/modules/user/src/RoleForm.php b/core/modules/user/src/RoleForm.php index 2bed647..b2eb7d8 100644 --- a/core/modules/user/src/RoleForm.php +++ b/core/modules/user/src/RoleForm.php @@ -58,7 +58,7 @@ public function save(array $form, array &$form_state) { $entity->set('label', trim($entity->label())); $status = $entity->save(); - $edit_link = \Drupal::linkGenerator()->generateFromUrl($this->t('Edit'), $this->entity->urlInfo()); + $edit_link = \Drupal::l($this->t('Edit'), $this->entity->urlInfo()); if ($status == SAVED_UPDATED) { drupal_set_message($this->t('Role %label has been updated.', array('%label' => $entity->label()))); watchdog('user', 'Role %label has been updated.', array('%label' => $entity->label()), WATCHDOG_NOTICE, $edit_link); diff --git a/core/tests/Drupal/Tests/Core/DrupalTest.php b/core/tests/Drupal/Tests/Core/DrupalTest.php index 5ace241..67cdb41 100644 --- a/core/tests/Drupal/Tests/Core/DrupalTest.php +++ b/core/tests/Drupal/Tests/Core/DrupalTest.php @@ -7,6 +7,7 @@ namespace Drupal\Tests\Core; +use Drupal\Core\Url; use Drupal\Tests\UnitTestCase; /** @@ -294,7 +295,7 @@ public function testL() { ->will($this->returnValue('link_html_string')); $this->setMockContainerService('link_generator', $generator); - $this->assertInternalType('string', \Drupal::l('Test title', 'test_route', $route_parameters, $options)); + $this->assertInternalType('string', \Drupal::l('Test title', new Url('test_route', $route_parameters, $options))); } /** diff --git a/core/themes/seven/seven.theme b/core/themes/seven/seven.theme index c3e7a32..3be6895 100644 --- a/core/themes/seven/seven.theme +++ b/core/themes/seven/seven.theme @@ -8,6 +8,7 @@ use Drupal\Component\Utility\Xss; use Drupal\Core\Template\RenderWrapper; use Drupal\Component\Utility\String; +use Drupal\Core\Url; /** * Implements hook_preprocess_HOOK() for page templates. @@ -106,7 +107,8 @@ function seven_menu_local_task($variables) { $a_tag = l($link_text, $link['href'], $link['localized_options']); } else { - $a_tag = \Drupal::l($link_text, $link['route_name'], $link['route_parameters'], $link['localized_options']); + $url = new Url($link['route_name'], $link['route_parameters'], $link['localized_options']); + $a_tag = \Drupal::l($link_text, $url); } return '' . $a_tag . ''; @@ -150,7 +152,7 @@ function seven_custom_block_add_list($variables) { $content .= '
' . Xss::filterAdmin($type['description']) . '
'; $options = $type['localized_options']; $options['html'] = TRUE; - $output .= \Drupal::l($content, 'custom_block.add_form', array('custom_block_type' => $id), $options); + $output .= \Drupal::l($content, new Url('custom_block.add_form', array('custom_block_type' => $id), $options)); $output .= ''; } $output .= ''; @@ -246,7 +248,8 @@ function seven_menu_local_action($variables) { // routes. // @todo Figure out how to support local actions without a href properly. if ($link['href'] === '' && !empty($link['route_name'])) { - $output .= Drupal::l($link['title'], $link['route_name'], $link['route_parameters'], $link['localized_options']); + $url = new Url($link['route_name'], $link['route_parameters'], $link['localized_options']); + $output .= \Drupal::l($link['title'], $url); } else { $output .= l($link['title'], $link['href'], $link['localized_options']);