From a6492ce9d94906ca3fd57eadc08a7d9a33873880 Mon Sep 17 00:00:00 2001 From: webchick <drupal@webchick.net> Date: Sun, 28 Sep 2014 00:21:34 -0700 Subject: [PATCH] Issue #2343651 by xjm, tim.plunkett, Wim Leers, dinarcon, dawehner: Remove most remaining l() calls. --- core/authorize.php | 4 +-- core/includes/theme.inc | 2 +- .../Drupal/Component/Utility/UrlHelper.php | 2 +- core/lib/Drupal/Core/Updater/Module.php | 6 ++-- core/lib/Drupal/Core/Updater/Theme.php | 4 +-- .../src/Controller/AggregatorController.php | 2 +- core/modules/aggregator/src/FeedForm.php | 2 +- core/modules/block/block.module | 2 +- core/modules/book/book.module | 5 ++- core/modules/book/src/BookManager.php | 4 +-- .../book/src/Controller/BookController.php | 13 ++++--- .../book/src/Form/BookAdminEditForm.php | 2 +- core/modules/book/src/Tests/BookTest.php | 15 ++++++-- core/modules/comment/comment.module | 4 +-- core/modules/comment/src/CommentForm.php | 5 ++- .../ContentTranslationController.php | 15 ++++---- .../Field/FieldType/DateTimeFieldItemList.php | 2 +- .../src/Tests/Views/ViewsIntegrationTest.php | 9 +++-- core/modules/field/field.module | 2 +- .../modules/filter/src/Element/TextFormat.php | 2 +- core/modules/forum/forum.module | 4 +-- core/modules/forum/src/Form/ForumForm.php | 7 ++-- .../image/src/Tests/ImageFieldDisplayTest.php | 2 +- core/modules/locale/locale.install | 4 +-- core/modules/locale/locale.module | 4 +-- core/modules/locale/locale.pages.inc | 2 +- core/modules/node/node.admin.inc | 2 +- core/modules/node/node.install | 2 +- core/modules/node/node.module | 13 ++++--- core/modules/node/node.pages.inc | 2 +- core/modules/node/src/NodeForm.php | 2 +- core/modules/node/src/NodeTypeForm.php | 2 +- .../Tests/ResponsiveImageFieldDisplayTest.php | 2 +- .../Tests/SearchConfigSettingsFormTest.php | 2 +- .../search/src/Tests/SearchRankingTest.php | 2 +- .../shortcut/src/Form/SetCustomize.php | 2 +- .../src/Tests/StatisticsReportsTest.php | 2 +- core/modules/statistics/statistics.module | 35 ------------------- core/modules/syslog/syslog.module | 2 +- core/modules/system/system.api.php | 2 +- core/modules/system/system.install | 2 +- core/modules/system/system.module | 4 +-- .../src/Plugin/views/field/LinkEdit.php | 2 +- core/modules/taxonomy/src/TermForm.php | 9 +++-- .../taxonomy/src/Tests/TermIndexTest.php | 2 +- .../src/Tests/Views/TaxonomyFieldTidTest.php | 2 +- .../modules/toolbar_test/toolbar_test.module | 6 ++-- core/modules/tracker/tracker.pages.inc | 4 +-- core/modules/update/update.install | 2 +- core/modules/user/src/AccountForm.php | 2 +- .../user/src/Plugin/Block/UserLoginBlock.php | 4 +-- core/modules/user/src/RegisterForm.php | 2 +- .../src/Tests/UserAccountFormFieldsTest.php | 4 +++ core/modules/user/src/Tests/UserAdminTest.php | 2 ++ .../views/display/DisplayPluginBase.php | 2 +- .../Plugin/views/field/FieldPluginBase.php | 1 + .../views/src/Tests/DefaultViewsTest.php | 2 +- core/modules/views_ui/src/ViewEditForm.php | 32 ++++++++++++++--- 58 files changed, 154 insertions(+), 127 deletions(-) diff --git a/core/authorize.php b/core/authorize.php index b44c1215cfb6..8b44e369bfa0 100644 --- a/core/authorize.php +++ b/core/authorize.php @@ -109,8 +109,8 @@ function authorize_access_allowed() { } else { $links = array_merge($links, array( - l(t('Administration pages'), 'admin'), - l(t('Front page'), '<front>'), + \Drupal::l(t('Administration pages'), 'system.admin'), + \Drupal::l(t('Front page'), '<front>'), )); } diff --git a/core/includes/theme.inc b/core/includes/theme.inc index e7ec8df06ed8..c726d07299ad 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -948,7 +948,7 @@ function template_preprocess_status_messages(&$variables) { * class. I.e. we cannot yet convert this jQuery selector to a CSS selector: * jQuery('li:has("a.active")') * - * @see l() + * @see \Drupal\Core\Utility\LinkGenerator * @see \Drupal\Core\Utility\LinkGenerator::generate() * @see system_page_build() */ diff --git a/core/lib/Drupal/Component/Utility/UrlHelper.php b/core/lib/Drupal/Component/Utility/UrlHelper.php index 0c0e07dd2e89..cf87435ebe42 100644 --- a/core/lib/Drupal/Component/Utility/UrlHelper.php +++ b/core/lib/Drupal/Component/Utility/UrlHelper.php @@ -133,7 +133,7 @@ public static function filterQueryParameters(array $query, array $exclude = arra * - query: An array of query parameters from $url, if they exist. * - fragment: The fragment component from $url, if it exists. * - * @see l() + * @see \Drupal\Core\Utility\LinkGenerator * @see url() * @see http://tools.ietf.org/html/rfc3986 * diff --git a/core/lib/Drupal/Core/Updater/Module.php b/core/lib/Drupal/Core/Updater/Module.php index acc3028f03de..3d3dd4110f6e 100644 --- a/core/lib/Drupal/Core/Updater/Module.php +++ b/core/lib/Drupal/Core/Updater/Module.php @@ -98,9 +98,9 @@ public function getSchemaUpdates() { */ public function postInstallTasks() { return array( - l(t('Install another module'), 'admin/modules/install'), - l(t('Enable newly added modules'), 'admin/modules'), - l(t('Administration pages'), 'admin'), + \Drupal::l(t('Install another module'), 'update.module_install'), + \Drupal::l(t('Enable newly added modules'), 'system.modules_list'), + \Drupal::l(t('Administration pages'), 'system.admin'), ); } diff --git a/core/lib/Drupal/Core/Updater/Theme.php b/core/lib/Drupal/Core/Updater/Theme.php index 7e17dddb1eab..0f1ea5bf5315 100644 --- a/core/lib/Drupal/Core/Updater/Theme.php +++ b/core/lib/Drupal/Core/Updater/Theme.php @@ -82,8 +82,8 @@ public function postInstall() { */ public function postInstallTasks() { return array( - l(t('Install newly added themes'), 'admin/appearance'), - l(t('Administration pages'), 'admin'), + \Drupal::l(t('Install newly added themes'), 'system.themes_page'), + \Drupal::l(t('Administration pages'), 'system.admin'), ); } } diff --git a/core/modules/aggregator/src/Controller/AggregatorController.php b/core/modules/aggregator/src/Controller/AggregatorController.php index c11e70ea99d1..0f7080050852 100644 --- a/core/modules/aggregator/src/Controller/AggregatorController.php +++ b/core/modules/aggregator/src/Controller/AggregatorController.php @@ -121,7 +121,7 @@ public function adminOverview() { $rows = array(); foreach ($feeds as $feed) { $row = array(); - $row[] = l($feed->label(), "aggregator/sources/" . $feed->id()); + $row[] = $this->getLinkGenerator()->generateFromUrl($feed->label(), $feed->urlInfo()); $row[] = $this->dateFormatter->formatInterval($entity_manager->getStorage('aggregator_item')->getItemCount($feed), '1 item', '@count items'); $last_checked = $feed->getLastCheckedTime(); $refresh_rate = $feed->getRefreshRate(); diff --git a/core/modules/aggregator/src/FeedForm.php b/core/modules/aggregator/src/FeedForm.php index 1832cb5ad86b..71acbbd57b07 100644 --- a/core/modules/aggregator/src/FeedForm.php +++ b/core/modules/aggregator/src/FeedForm.php @@ -70,7 +70,7 @@ public function save(array $form, FormStateInterface $form_state) { $form_state->setRedirectUrl($feed->urlInfo('canonical')); } else { - $this->logger('aggregator')->notice('Feed %feed added.', array('%feed' => $feed->label(), 'link' => l($this->t('View'), 'admin/config/services/aggregator'))); + $this->logger('aggregator')->notice('Feed %feed added.', array('%feed' => $feed->label(), 'link' => \Drupal::l($this->t('View'), 'aggregator.admin_overview'))); drupal_set_message($this->t('The feed %feed has been added.', array('%feed' => $feed->label()))); } } diff --git a/core/modules/block/block.module b/core/modules/block/block.module index bcf550123d27..2b6d8bd4fd98 100644 --- a/core/modules/block/block.module +++ b/core/modules/block/block.module @@ -41,7 +41,7 @@ function block_help($route_name, RouteMatchInterface $route_match) { $demo_theme = $route_match->getParameter('theme') ?: \Drupal::config('system.theme')->get('default'); $themes = list_themes(); $output = '<p>' . t('This page provides a drag-and-drop interface for adding a block to a region, and for controlling the order of blocks within regions. To add a block to a region, or to configure its specific title and visibility settings, click the block title under <em>Place blocks</em>. Since not all themes implement the same regions, or display regions in the same way, blocks are positioned on a per-theme basis. Remember that your changes will not be saved until you click the <em>Save blocks</em> button at the bottom of the page.') . '</p>'; - $output .= '<p>' . l(t('Demonstrate block regions (!theme)', array('!theme' => $themes[$demo_theme]->info['name'])), 'admin/structure/block/demo/' . $demo_theme) . '</p>'; + $output .= '<p>' . \Drupal::l(t('Demonstrate block regions (!theme)', array('!theme' => $themes[$demo_theme]->info['name'])), 'block.admin_demo', array('theme' => $demo_theme)) . '</p>'; return $output; } } diff --git a/core/modules/book/book.module b/core/modules/book/book.module index 861ed7321b1e..5fd5d2108ae1 100644 --- a/core/modules/book/book.module +++ b/core/modules/book/book.module @@ -518,7 +518,10 @@ function theme_book_link(array $variables) { $sub_menu = drupal_render($element['#below']); } $element['#localized_options']['set_active_class'] = TRUE; - $output = l($element['#title'], $element['#href'], $element['#localized_options']); + /** @var \Drupal\Core\Url $url */ + $url = $element['#url']; + $url->setOptions($element['#localized_options'] + $url->getOptions()); + $output = \Drupal::linkGenerator()->generateFromUrl($element['#title'], $url); return '<li' . new Attribute($element['#attributes']) . '>' . $output . $sub_menu . "</li>\n"; } diff --git a/core/modules/book/src/BookManager.php b/core/modules/book/src/BookManager.php index 7d43f1fa8a85..efab6410e40e 100644 --- a/core/modules/book/src/BookManager.php +++ b/core/modules/book/src/BookManager.php @@ -99,7 +99,7 @@ protected function loadBooks() { foreach ($book_links as $link) { $nid = $link['nid']; if (isset($nodes[$nid]) && $nodes[$nid]->status) { - $link['link_path'] = 'node/' . $nid; + $link['url'] = $nodes[$nid]->urlInfo(); $link['title'] = $nodes[$nid]->label(); $link['type'] = $nodes[$nid]->bundle(); $this->books[$link['bid']] = $link; @@ -528,7 +528,7 @@ public function bookTreeOutput(array $tree) { $element['#attributes']['class'] = $class; $element['#title'] = $data['link']['title']; $node = $this->entityManager->getStorage('node')->load($data['link']['nid']); - $element['#href'] = $node->url(); + $element['#url'] = $node->urlInfo(); $element['#localized_options'] = !empty($data['link']['localized_options']) ? $data['link']['localized_options'] : array(); $element['#below'] = $data['below'] ? $this->bookTreeOutput($data['below']) : $data['below']; $element['#original_link'] = $data['link']; diff --git a/core/modules/book/src/Controller/BookController.php b/core/modules/book/src/Controller/BookController.php index 305a0b9ffbe8..dd467b966528 100644 --- a/core/modules/book/src/Controller/BookController.php +++ b/core/modules/book/src/Controller/BookController.php @@ -9,7 +9,7 @@ use Drupal\book\BookExport; use Drupal\book\BookManagerInterface; -use Drupal\Core\DependencyInjection\ContainerInjectionInterface; +use Drupal\Core\Controller\ControllerBase; use Drupal\node\NodeInterface; use Symfony\Component\DependencyInjection\Container; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -19,7 +19,7 @@ /** * Controller routines for book routes. */ -class BookController implements ContainerInjectionInterface { +class BookController extends ControllerBase { /** * The book manager. @@ -71,8 +71,13 @@ public function adminOverview() { $headers = array(t('Book'), t('Operations')); // Add any recognized books to the table list. foreach ($this->bookManager->getAllBooks() as $book) { + /** @var \Drupal\Core\Url $url */ + $url = $book->urlInfo(); + if (isset($book['options'])) { + $url->setOptions($book['options']); + } $row = array( - l($book['title'], $book['link_path'], isset($book['options']) ? $book['options'] : array()), + $this->getLinkGenerator()->generateFromUrl($book['title'], $url), ); $links = array(); $links['edit'] = array( @@ -105,7 +110,7 @@ public function adminOverview() { public function bookRender() { $book_list = array(); foreach ($this->bookManager->getAllBooks() as $book) { - $book_list[] = l($book['title'], $book['link_path']); + $book_list[] = $this->getLinkGenerator()->generateFromUrl($book['title'], $book['url']); } return array( '#theme' => 'item_list', diff --git a/core/modules/book/src/Form/BookAdminEditForm.php b/core/modules/book/src/Form/BookAdminEditForm.php index 9a2b754f743f..973f44a467de 100644 --- a/core/modules/book/src/Form/BookAdminEditForm.php +++ b/core/modules/book/src/Form/BookAdminEditForm.php @@ -121,7 +121,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) { $node->book['link_title'] = $values['title']; $node->setNewRevision(); $node->save(); - $this->logger('content')->notice('book: updated %title.', array('%title' => $node->label(), 'link' => l($this->t('View'), 'node/' . $node->id()))); + $this->logger('content')->notice('book: updated %title.', array('%title' => $node->label(), 'link' => $this->getLinkGenerator()->generateFromUrl($this->t('View'), $node->urlInfo()))); } } } diff --git a/core/modules/book/src/Tests/BookTest.php b/core/modules/book/src/Tests/BookTest.php index fff81f56a158..335e6b5f7d54 100644 --- a/core/modules/book/src/Tests/BookTest.php +++ b/core/modules/book/src/Tests/BookTest.php @@ -187,15 +187,24 @@ function checkBookNode(EntityInterface $node, $nodes, $previous = FALSE, $up = F // Check previous, up, and next links. if ($previous) { - $this->assertRaw(l('<b>‹</b> ' . $previous->label(), 'node/' . $previous->id(), array('html' => TRUE, 'attributes' => array('rel' => array('prev'), 'title' => t('Go to previous page')))), 'Previous page link found.'); + /** @var \Drupal\Core\Url $url */ + $url = $previous->urlInfo(); + $url->setOptions(array('html' => TRUE, 'attributes' => array('rel' => array('prev'), 'title' => t('Go to previous page')))); + $this->assertRaw(\Drupal::linkGenerator()->generateFromUrl('<b>‹</b> ' . $previous->label(), $url), 'Previous page link found.'); } if ($up) { - $this->assertRaw(l('Up', 'node/' . $up->id(), array('html'=> TRUE, 'attributes' => array('title' => t('Go to parent page')))), 'Up page link found.'); + /** @var \Drupal\Core\Url $url */ + $url = $up->urlInfo(); + $url->setOptions(array('html'=> TRUE, 'attributes' => array('title' => t('Go to parent page')))); + $this->assertRaw(\Drupal::linkGenerator()->generateFromUrl('Up', $url), 'Up page link found.'); } if ($next) { - $this->assertRaw(l($next->label() . ' <b>›</b>', 'node/' . $next->id(), array('html'=> TRUE, 'attributes' => array('rel' => array('next'), 'title' => t('Go to next page')))), 'Next page link found.'); + /** @var \Drupal\Core\Url $url */ + $url = $next->urlInfo(); + $url->setOptions(array('html'=> TRUE, 'attributes' => array('rel' => array('next'), 'title' => t('Go to next page')))); + $this->assertRaw(\Drupal::linkGenerator()->generateFromUrl($next->label() . ' <b>›</b>', $url), 'Next page link found.'); } // Compute the expected breadcrumb. diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index 5b1ed9b4db6e..d838125b396f 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -727,8 +727,8 @@ function template_preprocess_comment(&$variables) { $variables['signature'] = ''; } if (isset($comment->in_preview)) { - $variables['title'] = l($comment->getSubject(), ''); - $variables['permalink'] = l(t('Permalink'), ''); + $variables['title'] = \Drupal::l($comment->getSubject(), '<front>'); + $variables['permalink'] = \Drupal::l(t('Permalink'), '<front>'); } else { $uri = $comment->urlInfo(); diff --git a/core/modules/comment/src/CommentForm.php b/core/modules/comment/src/CommentForm.php index 32ed795d2b6e..84f1dcefc713 100644 --- a/core/modules/comment/src/CommentForm.php +++ b/core/modules/comment/src/CommentForm.php @@ -370,7 +370,10 @@ public function save(array $form, FormStateInterface $form_state) { $form_state->setValue('cid', $comment->id()); // Add a log entry. - $logger->notice('Comment posted: %subject.', array('%subject' => $comment->getSubject(), 'link' => l(t('View'), 'comment/' . $comment->id(), array('fragment' => 'comment-' . $comment->id())))); + $logger->notice('Comment posted: %subject.', array( + '%subject' => $comment->getSubject(), + 'link' => $this->getLinkGenerator()->generateFromUrl(t('View'), $comment->urlInfo()->setOption('fragment', 'comment-' . $comment->id())) + )); // Explain the approval queue if necessary. if (!$comment->isPublished()) { diff --git a/core/modules/content_translation/src/Controller/ContentTranslationController.php b/core/modules/content_translation/src/Controller/ContentTranslationController.php index 93b4887cc8cd..991d51c5ce4b 100644 --- a/core/modules/content_translation/src/Controller/ContentTranslationController.php +++ b/core/modules/content_translation/src/Controller/ContentTranslationController.php @@ -122,11 +122,13 @@ public function overview(Request $request, $entity_type_id = NULL) { $source = isset($entity->translation[$langcode]['source']) ? $entity->translation[$langcode]['source'] : ''; $is_original = $langcode == $original; $label = $entity->getTranslation($langcode)->label(); - $link = isset($links->links[$langcode]['href']) ? $links->links[$langcode] : array('href' => $entity->getSystemPath()); - $link += array('language' => $language); - $row_title = l($label, $link['href'], $link); + $link = isset($links->links[$langcode]['url']) ? $links->links[$langcode] : array('url' => $entity->urlInfo()); + if (!empty($link['url'])) { + $link['url']->setOption('language', $language); + $row_title = $this->getLinkGenerator()->generateFromUrl($label, $link['url']); + } - if (empty($link['href'])) { + if (empty($link['url'])) { $row_title = $is_original ? $label : $this->t('n/a'); } @@ -134,10 +136,7 @@ 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'] = array( - 'href' => $entity->getSystemPath('edit-form'), - 'language' => $language, - ); + $links['edit'] = $entity->urlInfo('edit-form')->toArray() + ['language' => $language]; } elseif (!$is_original && $handler->getTranslationAccess($entity, 'update')->isAllowed()) { $links['edit'] = $edit_url->toArray(); diff --git a/core/modules/datetime/src/Plugin/Field/FieldType/DateTimeFieldItemList.php b/core/modules/datetime/src/Plugin/Field/FieldType/DateTimeFieldItemList.php index e78a194e305e..aa0388251184 100644 --- a/core/modules/datetime/src/Plugin/Field/FieldType/DateTimeFieldItemList.php +++ b/core/modules/datetime/src/Plugin/Field/FieldType/DateTimeFieldItemList.php @@ -51,7 +51,7 @@ public function defaultValuesForm(array &$form, FormStateInterface $form_state) 'default_date' => array( '#type' => 'textfield', '#title' => t('Relative default value'), - '#description' => t("Describe a time by reference to the current day, like '+90 days' (90 days from the day the field is created) or '+1 Saturday' (the next Saturday). See !strtotime for more details.", array('!strtotime' => l('strtotime', 'http://www.php.net/manual/en/function.strtotime.php'))), + '#description' => t("Describe a time by reference to the current day, like '+90 days' (90 days from the day the field is created) or '+1 Saturday' (the next Saturday). See <a href=\"@url\">@strtotime</a> for more details.", array('@strtotime' => 'strtotime', '@url' => 'http://www.php.net/manual/en/function.strtotime.php')), '#default_value' => (isset($default_value[0]['default_date_type']) && $default_value[0]['default_date_type'] == static::DEFAULT_VALUE_CUSTOM) ? $default_value[0]['default_date'] : '', '#states' => array( 'visible' => array( diff --git a/core/modules/dblog/src/Tests/Views/ViewsIntegrationTest.php b/core/modules/dblog/src/Tests/Views/ViewsIntegrationTest.php index 59eb7fc0faca..7878f00a7d3d 100644 --- a/core/modules/dblog/src/Tests/Views/ViewsIntegrationTest.php +++ b/core/modules/dblog/src/Tests/Views/ViewsIntegrationTest.php @@ -40,6 +40,9 @@ class ViewsIntegrationTest extends ViewUnitTestBase { protected function setUp() { parent::setUp(); + // Rebuild the router, otherwise we can't generate links. + $this->container->get('router.builder')->rebuild(); + $this->installSchema('dblog', array('watchdog')); ViewTestData::createTestViews(get_class($this), array('dblog_test_views')); @@ -57,12 +60,12 @@ public function testIntegration() { // Setup a watchdog entry without tokens. $entries[] = array( 'message' => $this->randomMachineName(), - 'variables' => array('link' => l('Link', 'node/1')), + 'variables' => array('link' => \Drupal::l('Link', '<front>')), ); // Setup a watchdog entry with one token. $entries[] = array( 'message' => '@token1', - 'variables' => array('@token1' => $this->randomMachineName(), 'link' => l('Link', 'node/2')), + 'variables' => array('@token1' => $this->randomMachineName(), 'link' => \Drupal::l('Link', '<front>')), ); // Setup a watchdog entry with two tokens. $entries[] = array( @@ -72,7 +75,7 @@ public function testIntegration() { 'variables' => array( '@token1' => $this->randomMachineName(), '!token2' => $this->randomMachineName(), - 'link' => l('<object>Link</object>', 'node/2', array('html' => TRUE)), + 'link' => \Drupal::l('<object>Link</object>', '<front>'), ), ); $logger_factory = $this->container->get('logger.factory'); diff --git a/core/modules/field/field.module b/core/modules/field/field.module index a16a06b90e12..118e504dce9f 100644 --- a/core/modules/field/field.module +++ b/core/modules/field/field.module @@ -86,7 +86,7 @@ function field_help($route_name, RouteMatchInterface $route_match) { if (isset($info[$provider]['name'])) { $display = $info[$provider]['name']; if (\Drupal::moduleHandler()->implementsHook($provider, 'help')) { - $items[] = l($display, 'admin/help/' . $provider); + $items[] = \Drupal::l($display, 'help.page', array('name' => $provider)); } else { $items[] = $display; diff --git a/core/modules/filter/src/Element/TextFormat.php b/core/modules/filter/src/Element/TextFormat.php index 35d2bdfd7d22..14b03d7435f7 100644 --- a/core/modules/filter/src/Element/TextFormat.php +++ b/core/modules/filter/src/Element/TextFormat.php @@ -179,7 +179,7 @@ public static function processFormat(&$element, FormStateInterface $form_state, $element['format']['help'] = array( '#type' => 'container', '#attributes' => array('class' => array('filter-help')), - '#markup' => l(t('About text formats'), 'filter/tips', array('attributes' => array('target' => '_blank'))), + '#markup' => \Drupal::l(t('About text formats'), 'filter.tips_all', array(), array('attributes' => array('target' => '_blank'))), '#weight' => 0, ); diff --git a/core/modules/forum/forum.module b/core/modules/forum/forum.module index 2d683ae5fa22..f81f6a8dbe5e 100644 --- a/core/modules/forum/forum.module +++ b/core/modules/forum/forum.module @@ -536,11 +536,11 @@ function template_preprocess_forums(&$variables) { if ($variables['tid'] != $topic->forum_tid) { $variables['topics'][$id]->moved = TRUE; $variables['topics'][$id]->title = String::checkPlain($topic->getTitle()); - $variables['topics'][$id]->message = l(t('This topic has been moved'), "forum/$topic->forum_tid"); + $variables['topics'][$id]->message = \Drupal::l(t('This topic has been moved'), 'forum.page', ['taxonomy_term' => $topic->forum_tid]); } else { $variables['topics'][$id]->moved = FALSE; - $variables['topics'][$id]->title_link = l($topic->getTitle(), 'node/' . $topic->id()); + $variables['topics'][$id]->title_link = \Drupal::linkGenerator()->generateFromUrl($topic->getTitle(), $topic->urlInfo()); $variables['topics'][$id]->message = ''; } $forum_submitted = array('#theme' => 'forum_submitted', '#topic' => (object) array( diff --git a/core/modules/forum/src/Form/ForumForm.php b/core/modules/forum/src/Form/ForumForm.php index 8ee5f435f7e5..eaa6e09592a7 100644 --- a/core/modules/forum/src/Form/ForumForm.php +++ b/core/modules/forum/src/Form/ForumForm.php @@ -79,16 +79,19 @@ public function save(array $form, FormStateInterface $form_state) { $term_storage = $this->entityManager->getStorage('taxonomy_term'); $status = $term_storage->save($term); + $route_name = $this->urlStub == 'container' ? 'forum.edit_container' : 'forum.edit_forum'; + $route_parameters = ['taxonomy_term' => $term->id()]; + $link = \Drupal::l($this->t('Edit'), $route_name, $route_parameters); switch ($status) { case SAVED_NEW: drupal_set_message($this->t('Created new @type %term.', array('%term' => $term->getName(), '@type' => $this->forumFormType))); - $this->logger('forum')->notice('Created new @type %term.', array('%term' => $term->getName(), '@type' => $this->forumFormType, 'link' => l($this->t('Edit'), 'admin/structure/forum/edit/' . $this->urlStub . '/' . $term->id()))); + $this->logger('forum')->notice('Created new @type %term.', array('%term' => $term->getName(), '@type' => $this->forumFormType, 'link' => $link)); $form_state->setValue('tid', $term->id()); break; case SAVED_UPDATED: drupal_set_message($this->t('The @type %term has been updated.', array('%term' => $term->getName(), '@type' => $this->forumFormType))); - $this->logger('forum')->notice('Updated @type %term.', array('%term' => $term->getName(), '@type' => $this->forumFormType, 'link' => l($this->t('Edit'), 'admin/structure/forum/edit/' . $this->urlStub . '/' . $term->id()))); + $this->logger('forum')->notice('Updated @type %term.', array('%term' => $term->getName(), '@type' => $this->forumFormType, 'link' => $link)); break; } diff --git a/core/modules/image/src/Tests/ImageFieldDisplayTest.php b/core/modules/image/src/Tests/ImageFieldDisplayTest.php index d1736993f980..1e8fd61ac03c 100644 --- a/core/modules/image/src/Tests/ImageFieldDisplayTest.php +++ b/core/modules/image/src/Tests/ImageFieldDisplayTest.php @@ -85,7 +85,7 @@ function _testImageFieldFormatters($scheme) { '#width' => 40, '#height' => 20, ); - $default_output = l($image, file_create_url($image_uri), array('html' => TRUE)); + $default_output = '<a href="' . file_create_url($image_uri) . '">' . drupal_render($image) . '</a>'; $this->drupalGet('node/' . $nid); $cache_tags_header = $this->drupalGetHeader('X-Drupal-Cache-Tags'); $this->assertTrue(!preg_match('/ image_style\:/', $cache_tags_header), 'No image style cache tag found.'); diff --git a/core/modules/locale/locale.install b/core/modules/locale/locale.install index a9efce991824..c4a924694c47 100644 --- a/core/modules/locale/locale.install +++ b/core/modules/locale/locale.install @@ -260,7 +260,7 @@ function locale_requirements($phase) { if ($available_updates) { $requirements['locale_translation'] = array( 'title' => 'Translation update status', - 'value' => l(t('Updates available'), 'admin/reports/translations'), + 'value' => \Drupal::l(t('Updates available'), 'locale.translate_status'), 'severity' => REQUIREMENT_WARNING, 'description' => t('Updates available for: @languages. See the <a href="@updates">Available translation updates</a> page for more information.', array('@languages' => implode(', ', $available_updates), '@updates' => \Drupal::url('locale.translate_status'))), ); @@ -285,7 +285,7 @@ function locale_requirements($phase) { else { $requirements['locale_translation'] = array( 'title' => 'Translation update status', - 'value' => l(t('Can not determine status'), 'admin/reports/translations'), + 'value' => \Drupal::l(t('Can not determine status'), 'locale.translate_status'), 'severity' => REQUIREMENT_WARNING, 'description' => t('No translation status is available. See the <a href="@updates">Available translation updates</a> page for more information.', array('@updates' => \Drupal::url('locale.translate_status'))), ); diff --git a/core/modules/locale/locale.module b/core/modules/locale/locale.module index 01a0b8e710f8..d2db127685f2 100644 --- a/core/modules/locale/locale.module +++ b/core/modules/locale/locale.module @@ -594,13 +594,13 @@ function locale_form_language_admin_overview_form_alter(&$form, FormStateInterfa ); if (!$language->locked && ($langcode != 'en' || locale_translate_english())) { $form['languages'][$langcode]['locale_statistics'] = array( - '#markup' => l( + '#markup' => \Drupal::l( t('@translated/@total (@ratio%)', array( '@translated' => $stats[$langcode]['translated'], '@total' => $total_strings, '@ratio' => $stats[$langcode]['ratio'], )), - 'admin/config/regional/translate', + 'locale.translate_page', array(), array('query' => array('langcode' => $langcode)) ), ); diff --git a/core/modules/locale/locale.pages.inc b/core/modules/locale/locale.pages.inc index dd88364b8af8..d76a741fd980 100644 --- a/core/modules/locale/locale.pages.inc +++ b/core/modules/locale/locale.pages.inc @@ -157,5 +157,5 @@ function template_preprocess_locale_translation_last_check(&$variables) { $last = $variables['last']; $variables['last_checked'] = ($last != NULL); $variables['time'] = \Drupal::service('date.formatter')->formatInterval(REQUEST_TIME - $last); - $variables['link'] = l(t('Check manually'), 'admin/reports/translations/check', array('query' => drupal_get_destination())); + $variables['link'] = \Drupal::l(t('Check manually'), 'locale.check_translation', array(), array('query' => drupal_get_destination())); } diff --git a/core/modules/node/node.admin.inc b/core/modules/node/node.admin.inc index b0a806d1f5a4..e6b955e1a71e 100644 --- a/core/modules/node/node.admin.inc +++ b/core/modules/node/node.admin.inc @@ -128,7 +128,7 @@ function _node_mass_update_batch_process(array $nodes, array $updates, $load, $r $node = _node_mass_update_helper($node, $updates); // Store result for post-processing in the finished callback. - $context['results'][] = l($node->label(), 'node/' . $node->id()); + $context['results'][] = \Drupal::linkGenerator()->generateFromUrl($node->label(), $node->urlInfo()); // Update our progress information. $context['sandbox']['progress']++; diff --git a/core/modules/node/node.install b/core/modules/node/node.install index be6d938b502b..fbe4313c3862 100644 --- a/core/modules/node/node.install +++ b/core/modules/node/node.install @@ -32,7 +32,7 @@ function node_requirements($phase) { 'value' => $value, // The result of t() is safe and so is the result of l(). Preserving // safe object. - 'description' => SafeMarkup::set($description . ' ' . l(t('Rebuild permissions'), 'admin/reports/status/rebuild')), + 'description' => SafeMarkup::set($description . ' ' . \Drupal::l(t('Rebuild permissions'), 'node.configure_rebuild_confirm')), ); } return $requirements; diff --git a/core/modules/node/node.module b/core/modules/node/node.module index 091d6018a28d..c22e92ee4c4a 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -16,6 +16,7 @@ use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Url; use Symfony\Component\HttpFoundation\Response; +use Drupal\Core\Database\StatementInterface; use Drupal\Core\Database\Query\AlterableInterface; use Drupal\Core\Database\Query\SelectInterface; use Drupal\field\Entity\FieldStorageConfig; @@ -185,7 +186,7 @@ function node_entity_view_display_alter(EntityViewDisplayInterface $display, $co /** * Gathers a listing of links to nodes. * - * @param $result + * @param \Drupal\Core\Database\StatementInterface $result * A database result object from a query to fetch node entities. If your * query joins the {comment_entity_statistics} table so that the comment_count * field is available, a title attribute will be added to show the number of @@ -197,12 +198,14 @@ function node_entity_view_display_alter(EntityViewDisplayInterface $display, $co * A renderable array containing a list of linked node titles fetched from * $result, or FALSE if there are no rows in $result. */ -function node_title_list($result, $title = NULL) { +function node_title_list(StatementInterface $result, $title = NULL) { $items = array(); $num_rows = FALSE; - foreach ($result as $node) { - // Do not use $node->label() here, because $node comes from the database. - $items[] = l($node->title, 'node/' . $node->nid, !empty($node->comment_count) ? array('attributes' => array('title' => format_plural($node->comment_count, '1 comment', '@count comments'))) : array()); + foreach ($result as $row) { + // Do not use $node->label() or $node->urlInfo() here, because we only have + // database rows, not actual nodes. + $options = !empty($row->comment_count) ? array('attributes' => array('title' => format_plural($row->comment_count, '1 comment', '@count comments'))) : array(); + $items[] = \Drupal::linkGenerator()->generate($row->title, 'entity.node.canonical', ['node' => $row->nid], $options); $num_rows = TRUE; } diff --git a/core/modules/node/node.pages.inc b/core/modules/node/node.pages.inc index 517a5d5e9faa..a7d77698854b 100644 --- a/core/modules/node/node.pages.inc +++ b/core/modules/node/node.pages.inc @@ -31,7 +31,7 @@ function template_preprocess_node_add_list(&$variables) { foreach ($variables['content'] as $type) { $variables['types'][$type->type] = array( 'type' => $type->type, - 'add_link' => l($type->name, 'node/add/' . $type->type), + 'add_link' => \Drupal::l($type->name, 'node.add', array('node_type' => $type->type)), 'description' => Xss::filterAdmin($type->description), ); } diff --git a/core/modules/node/src/NodeForm.php b/core/modules/node/src/NodeForm.php index 45343d550067..a3c484fbc594 100644 --- a/core/modules/node/src/NodeForm.php +++ b/core/modules/node/src/NodeForm.php @@ -408,7 +408,7 @@ public function save(array $form, FormStateInterface $form_state) { $node = $this->entity; $insert = $node->isNew(); $node->save(); - $node_link = l(t('View'), 'node/' . $node->id()); + $node_link = $this->getLinkGenerator()->generateFromUrl(t('View'), $node->urlInfo()); $context = array('@type' => $node->getType(), '%title' => $node->label(), 'link' => $node_link); $t_args = array('@type' => node_get_type_label($node), '%title' => $node->label()); diff --git a/core/modules/node/src/NodeTypeForm.php b/core/modules/node/src/NodeTypeForm.php index e60ee828a311..e99d8604cdf9 100644 --- a/core/modules/node/src/NodeTypeForm.php +++ b/core/modules/node/src/NodeTypeForm.php @@ -230,7 +230,7 @@ public function save(array $form, FormStateInterface $form_state) { } elseif ($status == SAVED_NEW) { drupal_set_message(t('The content type %name has been added.', $t_args)); - $context = array_merge($t_args, array('link' => l(t('View'), 'admin/structure/types'))); + $context = array_merge($t_args, array('link' => \Drupal::l(t('View'), 'node.overview_types'))); $this->logger('node')->notice('Added content type %name.', $context); } diff --git a/core/modules/responsive_image/src/Tests/ResponsiveImageFieldDisplayTest.php b/core/modules/responsive_image/src/Tests/ResponsiveImageFieldDisplayTest.php index 44dab9b65273..9759544d96ba 100644 --- a/core/modules/responsive_image/src/Tests/ResponsiveImageFieldDisplayTest.php +++ b/core/modules/responsive_image/src/Tests/ResponsiveImageFieldDisplayTest.php @@ -115,7 +115,7 @@ public function _testResponsiveImageFieldFormatters($scheme) { '#width' => 40, '#height' => 20, ); - $default_output = l($image, file_create_url($image_uri), array('html' => TRUE)); + $default_output = '<a href="' . file_create_url($image_uri) . '">' . drupal_render($image) . '</a>'; $this->drupalGet('node/' . $nid); $cache_tags_header = $this->drupalGetHeader('X-Drupal-Cache-Tags'); $this->assertTrue(!preg_match('/ image_style\:/', $cache_tags_header), 'No image style cache tag found.'); diff --git a/core/modules/search/src/Tests/SearchConfigSettingsFormTest.php b/core/modules/search/src/Tests/SearchConfigSettingsFormTest.php index 2f554c445895..fde250aae855 100644 --- a/core/modules/search/src/Tests/SearchConfigSettingsFormTest.php +++ b/core/modules/search/src/Tests/SearchConfigSettingsFormTest.php @@ -48,7 +48,7 @@ protected function setUp() { // Link the node to itself to test that it's only indexed once. The content // also needs the word "pizza" so we can use it as the search keyword. $body_key = 'body[0][value]'; - $edit[$body_key] = l($node->label(), 'node/' . $node->id()) . ' pizza sandwich'; + $edit[$body_key] = \Drupal::linkGenerator()->generateFromUrl($node->label(), $node->urlInfo()) . ' pizza sandwich'; $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save and keep published')); $this->container->get('plugin.manager.search')->createInstance('node_search')->updateIndex(); diff --git a/core/modules/search/src/Tests/SearchRankingTest.php b/core/modules/search/src/Tests/SearchRankingTest.php index eb9d9a0b06de..c3c1c25c7ecd 100644 --- a/core/modules/search/src/Tests/SearchRankingTest.php +++ b/core/modules/search/src/Tests/SearchRankingTest.php @@ -218,7 +218,7 @@ public function testHTMLRankings() { foreach ($shuffled_tags as $tag) { switch ($tag) { case 'a': - $settings['body'] = array(array('value' => l('Drupal Rocks', 'node'), 'format' => 'full_html')); + $settings['body'] = array(array('value' => \Drupal::l('Drupal Rocks', '<front>'), 'format' => 'full_html')); break; case 'notag': $settings['body'] = array(array('value' => 'Drupal Rocks')); diff --git a/core/modules/shortcut/src/Form/SetCustomize.php b/core/modules/shortcut/src/Form/SetCustomize.php index 536828d13837..89ddf4e25627 100644 --- a/core/modules/shortcut/src/Form/SetCustomize.php +++ b/core/modules/shortcut/src/Form/SetCustomize.php @@ -52,7 +52,7 @@ public function form(array $form, FormStateInterface $form_state) { foreach ($this->entity->getShortcuts() as $shortcut) { $id = $shortcut->id(); $form['shortcuts']['links'][$id]['#attributes']['class'][] = 'draggable'; - $form['shortcuts']['links'][$id]['name']['#markup'] = l($shortcut->getTitle(), $shortcut->path->value); + $form['shortcuts']['links'][$id]['name']['#markup'] = $this->getLinkGenerator()->generateFromUrl($shortcut->getTitle(), $shortcut->getUrl()); $form['shortcuts']['links'][$id]['#weight'] = $shortcut->getWeight(); $form['shortcuts']['links'][$id]['weight'] = array( '#type' => 'weight', diff --git a/core/modules/statistics/src/Tests/StatisticsReportsTest.php b/core/modules/statistics/src/Tests/StatisticsReportsTest.php index 520e6a430ccc..91b5fa466537 100644 --- a/core/modules/statistics/src/Tests/StatisticsReportsTest.php +++ b/core/modules/statistics/src/Tests/StatisticsReportsTest.php @@ -49,7 +49,7 @@ function testPopularContentBlock() { $this->assertText('All time', 'Found the all time popular content.'); $this->assertText('Last viewed', 'Found the last viewed popular content.'); - $this->assertRaw(l($node->label(), 'node/' . $node->id()), 'Found link to visited node.'); + $this->assertRaw(\Drupal::linkGenerator()->generateFromUrl($node->label(), $node->urlInfo()), 'Found link to visited node.'); } } diff --git a/core/modules/statistics/statistics.module b/core/modules/statistics/statistics.module index 7e4927b68f2b..3c80cd83ae1f 100644 --- a/core/modules/statistics/statistics.module +++ b/core/modules/statistics/statistics.module @@ -146,41 +146,6 @@ function statistics_get($nid) { } } -/** - * Generates a link to a path, truncating the displayed text to a given width. - * - * @param string $path - * The path to generate the link for. - * @param int $width - * The width to set the displayed text of the path. - * - * @return string - * A string as a link, truncated to the width, linked to the given $path. - */ -function _statistics_link($path, $width = 35) { - $title = \Drupal::service('path.alias_manager')->getAliasByPath($path); - $title = truncate_utf8($title, $width, FALSE, TRUE); - return l($title, $path); -} - -/** - * Formats an item for display, including both the item title and the link. - * - * @param string $title - * The text to link to a path; will be truncated to a maximum width of 35. - * @param string $path - * The path to link to; will default to '/'. - * - * @return string - * An HTML string with $title linked to the $path. - */ -function _statistics_format_item($title, $path) { - $path = ($path ? $path : '/'); - $output = ($title ? "$title<br />" : ''); - $output .= _statistics_link($path); - return $output; -} - /** * Implements hook_ENTITY_TYPE_predelete() for node entities. */ diff --git a/core/modules/syslog/syslog.module b/core/modules/syslog/syslog.module index 85a7311a6a53..3124b5037e77 100644 --- a/core/modules/syslog/syslog.module +++ b/core/modules/syslog/syslog.module @@ -33,7 +33,7 @@ function syslog_help($route_name, RouteMatchInterface $route_match) { */ function syslog_form_system_logging_settings_alter(&$form, FormStateInterface $form_state) { $config = \Drupal::config('syslog.settings'); - $help = \Drupal::moduleHandler()->moduleExists('help') ? ' ' . l(t('More information'), 'admin/help/syslog') . '.' : NULL; + $help = \Drupal::moduleHandler()->moduleExists('help') ? ' ' . \Drupal::l(t('More information'), 'help.page', ['name' => 'syslog']) . '.' : NULL; $form['syslog_identity'] = array( '#type' => 'textfield', '#title' => t('Syslog identity'), diff --git a/core/modules/system/system.api.php b/core/modules/system/system.api.php index f1c9b23233c3..ebe1b15c2cb8 100644 --- a/core/modules/system/system.api.php +++ b/core/modules/system/system.api.php @@ -1565,7 +1565,7 @@ function hook_requirements($phase) { // Test PHP version $requirements['php'] = array( 'title' => t('PHP'), - 'value' => ($phase == 'runtime') ? l(phpversion(), 'admin/reports/status/php') : phpversion(), + 'value' => ($phase == 'runtime') ? \Drupal::l(phpversion(), 'system.php') : phpversion(), ); if (version_compare(phpversion(), DRUPAL_MINIMUM_PHP) < 0) { $requirements['php']['description'] = t('Your PHP installation is too old. Drupal requires at least PHP %version.', array('%version' => DRUPAL_MINIMUM_PHP)); diff --git a/core/modules/system/system.install b/core/modules/system/system.install index 041e04f5eb9c..4d3ba7e510c4 100644 --- a/core/modules/system/system.install +++ b/core/modules/system/system.install @@ -59,7 +59,7 @@ function system_requirements($phase) { $requirements['php'] = array( 'title' => t('PHP'), // $phpversion is safe and output of l() is safe, so this value is safe. - 'value' => SafeMarkup::set(($phase == 'runtime') ? $phpversion . ' (' . l(t('more information'), 'admin/reports/status/php') . ')' : $phpversion), + 'value' => SafeMarkup::set(($phase == 'runtime') ? $phpversion . ' (' . \Drupal::l(t('more information'), 'system.php') . ')' : $phpversion), ); } else { diff --git a/core/modules/system/system.module b/core/modules/system/system.module index c863fdd255f4..3f19f14d3be2 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -1175,10 +1175,10 @@ function system_time_zones($blank = NULL) { function theme_system_compact_link() { $output = '<div class="compact-link">'; if (system_admin_compact_mode()) { - $output .= l(t('Show descriptions'), 'admin/compact/off', array('attributes' => array('title' => t('Expand layout to include descriptions.')), 'query' => drupal_get_destination())); + $output .= \Drupal::l(t('Show descriptions'), 'system.admin_compact_page', array('mode' => 'off'), array('attributes' => array('title' => t('Expand layout to include descriptions.')), 'query' => drupal_get_destination())); } else { - $output .= l(t('Hide descriptions'), 'admin/compact/on', array('attributes' => array('title' => t('Compress layout by hiding descriptions.')), 'query' => drupal_get_destination())); + $output .= \Drupal::l(t('Hide descriptions'), 'system.admin_compact_page', array('mode' => 'on'), array('attributes' => array('title' => t('Compress layout by hiding descriptions.')), 'query' => drupal_get_destination())); } $output .= '</div>'; diff --git a/core/modules/taxonomy/src/Plugin/views/field/LinkEdit.php b/core/modules/taxonomy/src/Plugin/views/field/LinkEdit.php index 53cd3234c0e3..4a9820704f88 100644 --- a/core/modules/taxonomy/src/Plugin/views/field/LinkEdit.php +++ b/core/modules/taxonomy/src/Plugin/views/field/LinkEdit.php @@ -68,7 +68,7 @@ public function render(ResultRow $values) { )); if ($term->access('update')) { $text = !empty($this->options['text']) ? $this->options['text'] : $this->t('Edit'); - return l($text, 'taxonomy/term/'. $tid . '/edit', array('query' => drupal_get_destination())); + return \Drupal::l($text, 'entity.taxonomy.edit_form', ['taxonomy_term' => $tid], array('query' => drupal_get_destination())); } } } diff --git a/core/modules/taxonomy/src/TermForm.php b/core/modules/taxonomy/src/TermForm.php index 2fa6f4b4427f..39ebb01a5c2d 100644 --- a/core/modules/taxonomy/src/TermForm.php +++ b/core/modules/taxonomy/src/TermForm.php @@ -134,14 +134,17 @@ public function buildEntity(array $form, FormStateInterface $form_state) { public function save(array $form, FormStateInterface $form_state) { $term = $this->entity; - switch ($term->save()) { + $result = $term->save(); + + $link = $this->getLinkGenerator()->generateFromUrl($this->t('Edit'), $term->urlInfo('edit-form')); + switch ($result) { case SAVED_NEW: drupal_set_message($this->t('Created new term %term.', array('%term' => $term->getName()))); - $this->logger('taxonomy')->notice('Created new term %term.', array('%term' => $term->getName(), 'link' => l($this->t('Edit'), 'taxonomy/term/' . $term->id() . '/edit'))); + $this->logger('taxonomy')->notice('Created new term %term.', array('%term' => $term->getName(), 'link' => $link)); break; case SAVED_UPDATED: drupal_set_message($this->t('Updated term %term.', array('%term' => $term->getName()))); - $this->logger('taxonomy')->notice('Updated term %term.', array('%term' => $term->getName(), 'link' => l($this->t('Edit'), 'taxonomy/term/' . $term->id() . '/edit'))); + $this->logger('taxonomy')->notice('Updated term %term.', array('%term' => $term->getName(), 'link' => $link)); break; } diff --git a/core/modules/taxonomy/src/Tests/TermIndexTest.php b/core/modules/taxonomy/src/Tests/TermIndexTest.php index 54d0dfb48638..8ad3968e9b33 100644 --- a/core/modules/taxonomy/src/Tests/TermIndexTest.php +++ b/core/modules/taxonomy/src/Tests/TermIndexTest.php @@ -217,6 +217,6 @@ function testTaxonomyTermHierarchyBreadcrumbs() { // Verify that the page breadcrumbs include a link to the parent term. $this->drupalGet('taxonomy/term/' . $term1->id()); - $this->assertRaw(l($term2->getName(), 'taxonomy/term/' . $term2->id()), 'Parent term link is displayed when viewing the node.'); + $this->assertRaw(\Drupal::linkGenerator()->generateFromUrl($term2->getName(), $term2->urlInfo()), 'Parent term link is displayed when viewing the node.'); } } diff --git a/core/modules/taxonomy/src/Tests/Views/TaxonomyFieldTidTest.php b/core/modules/taxonomy/src/Tests/Views/TaxonomyFieldTidTest.php index 03b297988877..29f6f3bbb717 100644 --- a/core/modules/taxonomy/src/Tests/Views/TaxonomyFieldTidTest.php +++ b/core/modules/taxonomy/src/Tests/Views/TaxonomyFieldTidTest.php @@ -28,7 +28,7 @@ function testViewsHandlerTidField() { $this->executeView($view); $actual = $view->field['name']->advancedRender($view->result[0]); - $expected = l($this->term1->label(), $this->term1->getSystemPath()); + $expected = \Drupal::linkGenerator()->generateFromUrl($this->term1->label(), $this->term1->urlInfo()); $this->assertEqual($expected, $actual); } 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 bc2ce9989dd1..d167f92aeb6a 100644 --- a/core/modules/toolbar/tests/modules/toolbar_test/toolbar_test.module +++ b/core/modules/toolbar/tests/modules/toolbar_test/toolbar_test.module @@ -32,9 +32,9 @@ function toolbar_test_toolbar() { 'content' => array( '#theme' => 'item_list', '#items' => array( - l(t('link 1'), '<front>', array('attributes' => array('title' => 'Test link 1 title'))), - l(t('link 2'), '<front>', array('attributes' => array('title' => 'Test link 2 title'))), - l(t('link 3'), '<front>', array('attributes' => array('title' => 'Test link 3 title'))), + \Drupal::l(t('link 1'), '<front>', [], array('attributes' => array('title' => 'Test link 1 title'))), + \Drupal::l(t('link 2'), '<front>', [], array('attributes' => array('title' => 'Test link 2 title'))), + \Drupal::l(t('link 3'), '<front>', [], array('attributes' => array('title' => 'Test link 3 title'))), ), '#attributes' => array( 'class' => array('menu'), diff --git a/core/modules/tracker/tracker.pages.inc b/core/modules/tracker/tracker.pages.inc index a88b75451654..f68cad7c561d 100644 --- a/core/modules/tracker/tracker.pages.inc +++ b/core/modules/tracker/tracker.pages.inc @@ -74,7 +74,7 @@ function tracker_page($account = NULL) { if ($new = \Drupal::service('comment.manager')->getCountNewComments($node)) { $comments .= '<br />'; - $comments .= l(format_plural($new, '1 new', '@count new'), 'node/' . $node->id(), array('fragment' => 'new')); + $comments .= \Drupal::linkGenerator()->generateFromUrl(format_plural($new, '1 new', '@count new'), $node->urlInfo()->setOptions(array('fragment' => 'new'))); } } @@ -85,7 +85,7 @@ function tracker_page($account = NULL) { $row = array( 'type' => String::checkPlain(node_get_type_label($node)), - 'title' => array('data' => l($node->getTitle(), 'node/' . $node->id()) . ' ' . drupal_render($mark_build)), + 'title' => array('data' => \Drupal::linkGenerator()->generateFromUrl($node->getTitle(), $node->urlInfo()) . ' ' . drupal_render($mark_build)), 'author' => array('data' => array('#theme' => 'username', '#account' => $node->getOwner())), 'replies' => array('class' => array('replies'), 'data' => $comments), 'last updated' => array('data' => t('!time ago', array('!time' => \Drupal::service('date.formatter')->formatInterval(REQUEST_TIME - $node->last_activity)))), diff --git a/core/modules/update/update.install b/core/modules/update/update.install index 7997ec87d090..fa04937b7a9b 100644 --- a/core/modules/update/update.install +++ b/core/modules/update/update.install @@ -134,6 +134,6 @@ function _update_requirement_check($project, $type) { if ($status != UPDATE_CURRENT && $type == 'core' && isset($project['recommended'])) { $requirement_label .= ' ' . t('(version @version available)', array('@version' => $project['recommended'])); } - $requirement['value'] = l($requirement_label, update_manager_access() ? 'admin/reports/updates/update' : 'admin/reports/updates'); + $requirement['value'] = \Drupal::l($requirement_label, update_manager_access() ? 'update.report_update' : 'update.status'); return $requirement; } diff --git a/core/modules/user/src/AccountForm.php b/core/modules/user/src/AccountForm.php index 1b89bf5f9601..57b29f443ab8 100644 --- a/core/modules/user/src/AccountForm.php +++ b/core/modules/user/src/AccountForm.php @@ -132,7 +132,7 @@ public function form(array $form, FormStateInterface $form_state) { if (!$pass_reset) { $protected_values['mail'] = $form['account']['mail']['#title']; $protected_values['pass'] = $this->t('Password'); - $request_new = l($this->t('Request new password'), 'user/password', array('attributes' => array('title' => $this->t('Request new password via email.')))); + $request_new = \Drupal::l($this->t('Request new password'), 'user.pass', array(), array('attributes' => array('title' => $this->t('Request new password via email.')))); $current_pass_description = $this->t('Required if you want to change the %mail or %pass below. !request_new.', array('%mail' => $protected_values['mail'], '%pass' => $protected_values['pass'], '!request_new' => $request_new)); } diff --git a/core/modules/user/src/Plugin/Block/UserLoginBlock.php b/core/modules/user/src/Plugin/Block/UserLoginBlock.php index 7b3727dbcf06..d93ee2f944d8 100644 --- a/core/modules/user/src/Plugin/Block/UserLoginBlock.php +++ b/core/modules/user/src/Plugin/Block/UserLoginBlock.php @@ -44,14 +44,14 @@ public function build() { // Build action links. $items = array(); if (\Drupal::config('user.settings')->get('register') != USER_REGISTER_ADMINISTRATORS_ONLY) { - $items['create_account'] = l(t('Create new account'), 'user/register', array( + $items['create_account'] = \Drupal::l(t('Create new account'), 'user.register', array(), array( 'attributes' => array( 'title' => t('Create a new user account.'), 'class' => array('create-account-link'), ), )); } - $items['request_password'] = l(t('Request new password'), 'user/password', array( + $items['request_password'] = \Drupal::l(t('Request new password'), 'user.pass', array(), array( 'attributes' => array( 'title' => t('Request new password via email.'), 'class' => array('request-password-link'), diff --git a/core/modules/user/src/RegisterForm.php b/core/modules/user/src/RegisterForm.php index 9ca0c95b843d..fbf09003e565 100644 --- a/core/modules/user/src/RegisterForm.php +++ b/core/modules/user/src/RegisterForm.php @@ -115,7 +115,7 @@ public function save(array $form, FormStateInterface $form_state) { $form_state->set('user', $account); $form_state->setValue('uid', $account->id()); - $this->logger('user')->notice('New user: %name %email.', array('%name' => $form_state->getValue('name'), '%email' => '<' . $form_state->getValue('mail') . '>', 'type' => l($this->t('Edit'), 'user/' . $account->id() . '/edit'))); + $this->logger('user')->notice('New user: %name %email.', array('%name' => $form_state->getValue('name'), '%email' => '<' . $form_state->getValue('mail') . '>', 'type' => \Drupal::l($this->t('Edit'), 'entity.user.edit_form', array('user' => $account->id())))); // Add plain text password into user account to generate mail tokens. $account->password = $pass; diff --git a/core/modules/user/src/Tests/UserAccountFormFieldsTest.php b/core/modules/user/src/Tests/UserAccountFormFieldsTest.php index df01adcdcbad..e242a07946f3 100644 --- a/core/modules/user/src/Tests/UserAccountFormFieldsTest.php +++ b/core/modules/user/src/Tests/UserAccountFormFieldsTest.php @@ -79,6 +79,10 @@ function testUserEditForm() { // Install default configuration; required for AccountFormController. $this->installConfig(array('user')); + // Install the router table and then rebuild. + $this->installSchema('system', ['router']); + \Drupal::service('router.builder')->rebuild(); + $form = $this->buildAccountForm('default'); // Verify name and pass field order. diff --git a/core/modules/user/src/Tests/UserAdminTest.php b/core/modules/user/src/Tests/UserAdminTest.php index 1d236c4293dd..3b18295f5596 100644 --- a/core/modules/user/src/Tests/UserAdminTest.php +++ b/core/modules/user/src/Tests/UserAdminTest.php @@ -52,6 +52,8 @@ function testUserAdmin() { $this->assertText($admin_user->getUsername(), 'Found Admin user on admin users page'); // Test for existence of edit link in table. + // @todo This cannot be converted to \Drupal::l() until + // https://www.drupal.org/node/2345725 is resolved. $link = l(t('Edit'), "user/" . $user_a->id() . "/edit", array('query' => array('destination' => 'admin/people'))); $this->assertRaw($link, 'Found user A edit link on admin users page'); diff --git a/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php b/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php index 2d4211746b91..5348df19f0ca 100644 --- a/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php +++ b/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php @@ -1034,7 +1034,7 @@ public function optionLink($text, $section, $class = '', $title = '') { $title = $text; } - return l($text, 'admin/structure/views/nojs/display/' . $this->view->storage->id() . '/' . $this->display['id'] . '/' . $section, array('attributes' => array('class' => array('views-ajax-link', $class), 'title' => $title, 'id' => drupal_html_id('views-' . $this->display['id'] . '-' . $section)), 'html' => TRUE)); + return \Drupal::l($text, 'views_ui.form_display', ['js' => 'nojs', 'view' => $this->view->storage->id(), 'display_id' => $this->display['id'], 'type' => $section], array('attributes' => array('class' => array('views-ajax-link', $class), 'title' => $title, 'id' => drupal_html_id('views-' . $this->display['id'] . '-' . $section)), 'html' => TRUE)); } /** diff --git a/core/modules/views/src/Plugin/views/field/FieldPluginBase.php b/core/modules/views/src/Plugin/views/field/FieldPluginBase.php index 3466e55a8c0d..c6f0c1e010e1 100644 --- a/core/modules/views/src/Plugin/views/field/FieldPluginBase.php +++ b/core/modules/views/src/Plugin/views/field/FieldPluginBase.php @@ -13,6 +13,7 @@ use Drupal\Component\Utility\UrlHelper; use Drupal\Component\Utility\Xss; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Url; use Drupal\views\Plugin\views\HandlerBase; use Drupal\views\Plugin\views\display\DisplayPluginBase; use Drupal\views\ResultRow; diff --git a/core/modules/views/src/Tests/DefaultViewsTest.php b/core/modules/views/src/Tests/DefaultViewsTest.php index 301fc2c5a0a2..c02e6e86fceb 100644 --- a/core/modules/views/src/Tests/DefaultViewsTest.php +++ b/core/modules/views/src/Tests/DefaultViewsTest.php @@ -94,7 +94,7 @@ protected function setUp() { if ($i % 2) { $values['promote'] = TRUE; } - $values['body'][]['value'] = l('Node ' . 1, 'node/' . 1); + $values['body'][]['value'] = \Drupal::l('Node ' . 1, 'entity.node.canonical', ['node' => 1]); $node = $this->drupalCreateNode($values); diff --git a/core/modules/views_ui/src/ViewEditForm.php b/core/modules/views_ui/src/ViewEditForm.php index eda64cc6b354..12083cfd8f46 100644 --- a/core/modules/views_ui/src/ViewEditForm.php +++ b/core/modules/views_ui/src/ViewEditForm.php @@ -1062,7 +1062,13 @@ public function getFormBucket(ViewUI $view, $type, $display) { if ($handler->broken()) { $build['fields'][$id]['#class'][] = 'broken'; $field_name = $handler->adminLabel(); - $build['fields'][$id]['#link'] = l($field_name, "admin/structure/views/nojs/handler/{$view->id()}/{$display['id']}/$type/$id", array('attributes' => array('class' => array('views-ajax-link')), 'html' => TRUE)); + $build['fields'][$id]['#link'] = \Drupal::l($field_name, 'views_ui.form_handler', array( + 'js' => 'nojs', + 'view' => $view->id(), + 'display_id' => $display['id'], + 'type' => $type, + 'id' => $id, + ), array('attributes' => array('class' => array('views-ajax-link')), 'html' => TRUE)); continue; } @@ -1079,15 +1085,33 @@ public function getFormBucket(ViewUI $view, $type, $display) { // Add a [hidden] marker, if the field is excluded. $link_text .= ' [' . $this->t('hidden') . ']'; } - $build['fields'][$id]['#link'] = l($link_text, "admin/structure/views/nojs/handler/{$view->id()}/{$display['id']}/$type/$id", array('attributes' => $link_attributes, 'html' => TRUE)); + $build['fields'][$id]['#link'] = \Drupal::l($link_text, 'views_ui.form_handler', array( + 'js' => 'nojs', + 'view' => $view->id(), + 'display_id' => $display['id'], + 'type' => $type, + 'id' => $id, + ), array('attributes' => $link_attributes, 'html' => TRUE)); $build['fields'][$id]['#class'][] = drupal_clean_css_identifier($display['id']. '-' . $type . '-' . $id); if ($executable->display_handler->useGroupBy() && $handler->usesGroupBy()) { - $build['fields'][$id]['#settings_links'][] = l('<span class="label">' . $this->t('Aggregation settings') . '</span>', "admin/structure/views/nojs/handler-group/{$view->id()}/{$display['id']}/$type/$id", array('attributes' => array('class' => array('views-button-configure', 'views-ajax-link'), 'title' => $this->t('Aggregation settings')), 'html' => TRUE)); + $build['fields'][$id]['#settings_links'][] = \Drupal::l('<span class="label">' . $this->t('Aggregation settings') . '</span>', 'views_ui.form_handler_group', array( + 'js' => 'nojs', + 'view' => $view->id(), + 'display_id' => $display['id'], + 'type' => $type, + 'id' => $id, + ), array('attributes' => array('class' => array('views-button-configure', 'views-ajax-link'), 'title' => $this->t('Aggregation settings')), 'html' => TRUE)); } if ($handler->hasExtraOptions()) { - $build['fields'][$id]['#settings_links'][] = l('<span class="label">' . $this->t('Settings') . '</span>', "admin/structure/views/nojs/handler-extra/{$view->id()}/{$display['id']}/$type/$id", array('attributes' => array('class' => array('views-button-configure', 'views-ajax-link'), 'title' => $this->t('Settings')), 'html' => TRUE)); + $build['fields'][$id]['#settings_links'][] = \Drupal::l('<span class="label">' . $this->t('Settings') . '</span>', 'views_ui.form_handler_extra', array( + 'js' => 'nojs', + 'view' => $view->id(), + 'display_id' => $display['id'], + 'type' => $type, + 'id' => $id, + ), array('attributes' => array('class' => array('views-button-configure', 'views-ajax-link'), 'title' => $this->t('Settings')), 'html' => TRUE)); } if ($grouping) { -- GitLab