From 46e6a32911d99efc17aff3371a274558f5604a56 Mon Sep 17 00:00:00 2001 From: Alex Pott Date: Tue, 4 Nov 2014 08:30:21 +0000 Subject: [PATCH] Issue #2364161 by dawehner, mpdonadio, Wim Leers: Replace nearly all existing _l calls. --- .../Drupal/Core/Template/TwigExtension.php | 9 ++---- .../src/Tests/Views/IntegrationTest.php | 3 +- .../dblog/src/Controller/DbLogController.php | 4 +-- core/modules/file/file.module | 3 +- core/modules/link/link.module | 7 +---- core/modules/link/src/Tests/LinkFieldTest.php | 5 +-- .../path/src/Controller/PathController.php | 4 +-- .../responsive_image/responsive_image.module | 3 +- .../system/src/Tests/Common/UrlTest.php | 4 +-- .../update/src/Form/UpdateManagerUpdate.php | 5 +-- .../update/src/Tests/UpdateContribTest.php | 29 ++++++++--------- .../update/src/Tests/UpdateCoreTest.php | 20 ++++++------ .../update/src/Tests/UpdateTestBase.php | 3 +- .../user/src/Plugin/views/field/LinkEdit.php | 3 +- core/modules/user/src/Tests/UserAdminTest.php | 4 +-- .../Plugin/views/field/FieldPluginBase.php | 31 +++++++++++++++++-- .../views/src/Plugin/views/field/Links.php | 6 +++- .../views/src/Tests/Handler/FieldUrlTest.php | 3 +- .../views_ui/src/Form/Ajax/Rearrange.php | 3 +- core/modules/views_ui/src/ViewListBuilder.php | 3 +- core/modules/views_ui/src/ViewUI.php | 3 +- core/modules/views_ui/views_ui.theme.inc | 2 +- 22 files changed, 95 insertions(+), 62 deletions(-) diff --git a/core/lib/Drupal/Core/Template/TwigExtension.php b/core/lib/Drupal/Core/Template/TwigExtension.php index 632e42a1a85..65fa8cc6c1a 100644 --- a/core/lib/Drupal/Core/Template/TwigExtension.php +++ b/core/lib/Drupal/Core/Template/TwigExtension.php @@ -209,13 +209,10 @@ class TwigExtension extends \Twig_Extension { * An HTML string containing a link to the given url. */ public function getLink($text, $url) { - if ($url instanceof Url) { - return $this->linkGenerator->generate($text, $url); - } - else { - // @todo Convert once https://www.drupal.org/node/2306901 is in - return _l($text, $url); + if (!$url instanceof Url) { + $url = Url::fromUri($url); } + return $this->linkGenerator->generate($text, $url); } /** diff --git a/core/modules/aggregator/src/Tests/Views/IntegrationTest.php b/core/modules/aggregator/src/Tests/Views/IntegrationTest.php index e4bb5fc2111..4e26255ab15 100644 --- a/core/modules/aggregator/src/Tests/Views/IntegrationTest.php +++ b/core/modules/aggregator/src/Tests/Views/IntegrationTest.php @@ -7,6 +7,7 @@ namespace Drupal\aggregator\Tests\Views; +use Drupal\Core\Url; use Drupal\views\Views; use Drupal\views\Tests\ViewTestData; use Drupal\views\Tests\ViewUnitTestBase; @@ -107,7 +108,7 @@ class IntegrationTest extends ViewUnitTestBase { // Ensure that the rendering of the linked title works as expected. foreach ($view->result as $row) { $iid = $view->field['iid']->getValue($row); - $expected_link = _l($items[$iid]->getTitle(), $items[$iid]->getLink(), array('absolute' => TRUE)); + $expected_link = \Drupal::l($items[$iid]->getTitle(), Url::fromUri($items[$iid]->getLink(), ['absolute' => TRUE])); $this->assertEqual($view->field['title']->advancedRender($row), $expected_link, 'Ensure the right link is generated'); $expected_author = aggregator_filter_xss($items[$iid]->getAuthor()); diff --git a/core/modules/dblog/src/Controller/DbLogController.php b/core/modules/dblog/src/Controller/DbLogController.php index ded98dd9f7f..2ef2d066dff 100644 --- a/core/modules/dblog/src/Controller/DbLogController.php +++ b/core/modules/dblog/src/Controller/DbLogController.php @@ -254,11 +254,11 @@ class DbLogController extends ControllerBase { ), array( array('data' => $this->t('Location'), 'header' => TRUE), - _l($dblog->location, $dblog->location), + $this->l($dblog->location, $dblog->location ? Url::fromUri('base://' . $dblog->location) : Url::fromRoute('')), ), array( array('data' => $this->t('Referrer'), 'header' => TRUE), - _l($dblog->referer, $dblog->referer), + $this->l($dblog->referer, $dblog->referer ? Url::fromUri('base://' . $dblog->referer) : Url::fromRoute('')), ), array( array('data' => $this->t('Message'), 'header' => TRUE), diff --git a/core/modules/file/file.module b/core/modules/file/file.module index 9f83add3daf..fdee4baf6d4 100644 --- a/core/modules/file/file.module +++ b/core/modules/file/file.module @@ -11,6 +11,7 @@ use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Render\Element; use Drupal\Core\Routing\RouteMatchInterface; +use Drupal\Core\Url; use Drupal\file\Entity\File; use Drupal\file\FileInterface; use Drupal\Component\Utility\NestedArray; @@ -1259,7 +1260,7 @@ function template_preprocess_file_link(&$variables) { $options['attributes']['title'] = String::checkPlain($file_entity->getFilename()); } - $variables['link'] = _l($link_text, $url, $options); + $variables['link'] = \Drupal::l($link_text, Url::fromUri($url, $options)); $variables['attributes'] = array('class' => array('file')); } diff --git a/core/modules/link/link.module b/core/modules/link/link.module index 72ae02405e0..142f8476b58 100644 --- a/core/modules/link/link.module +++ b/core/modules/link/link.module @@ -64,10 +64,5 @@ function template_preprocess_link_formatter_link_separate(&$variables) { $variables['title'] = String::checkPlain($variables['title']); } - if (!$variables['url']->isExternal()) { - $variables['link'] = \Drupal::l($variables['url_title'], $variables['url']); - } - else { - $variables['link'] = _l($variables['url_title'], $variables['url']->getUri(), $variables['url']->getOptions()); - } + $variables['link'] = \Drupal::l($variables['url_title'], $variables['url']); } diff --git a/core/modules/link/src/Tests/LinkFieldTest.php b/core/modules/link/src/Tests/LinkFieldTest.php index 7a4b0968881..8160782a0dd 100644 --- a/core/modules/link/src/Tests/LinkFieldTest.php +++ b/core/modules/link/src/Tests/LinkFieldTest.php @@ -9,6 +9,7 @@ namespace Drupal\link\Tests; use Drupal\Component\Utility\String; use Drupal\Component\Utility\Unicode; +use Drupal\Core\Url; use Drupal\link\LinkItemInterface; use Drupal\simpletest\WebTestBase; @@ -276,7 +277,7 @@ class LinkFieldTest extends WebTestBase { $this->assertText(t('entity_test @id has been created.', array('@id' => $id))); $this->renderTestEntity($id); - $expected_link = _l($value, $value); + $expected_link = \Drupal::l($value, Url::fromUri($value)); $this->assertRaw($expected_link); // Verify that a link with text is rendered using the link text. @@ -288,7 +289,7 @@ class LinkFieldTest extends WebTestBase { $this->assertText(t('entity_test @id has been updated.', array('@id' => $id))); $this->renderTestEntity($id); - $expected_link = _l($title, $value); + $expected_link = \Drupal::l($title, Url::fromUri($value)); $this->assertRaw($expected_link); } diff --git a/core/modules/path/src/Controller/PathController.php b/core/modules/path/src/Controller/PathController.php index e664a85ebc7..6d94debe0fa 100644 --- a/core/modules/path/src/Controller/PathController.php +++ b/core/modules/path/src/Controller/PathController.php @@ -89,10 +89,10 @@ class PathController extends ControllerBase { $row['data']['alias'] = _l(Unicode::truncate($data->alias, 50, FALSE, TRUE), $data->source, array( 'attributes' => array('title' => $data->alias), )); - $row['data']['source'] = _l(Unicode::truncate($data->source, 50, FALSE, TRUE), $data->source, array( + $row['data']['source'] = $this->l(Unicode::truncate($data->source, 50, FALSE, TRUE), Url::fromUri('base://' . $data->source, array( 'alias' => TRUE, 'attributes' => array('title' => $data->source), - )); + ))); if ($multilanguage) { $row['data']['language_name'] = $this->languageManager()->getLanguageName($data->langcode); } diff --git a/core/modules/responsive_image/responsive_image.module b/core/modules/responsive_image/responsive_image.module index 1071fb14efc..79928157af1 100644 --- a/core/modules/responsive_image/responsive_image.module +++ b/core/modules/responsive_image/responsive_image.module @@ -8,6 +8,7 @@ use Drupal\Component\Utility\SafeMarkup; use Drupal\Core\Routing\RouteMatchInterface; use \Drupal\Core\Template\Attribute; +use Drupal\Core\Url; use Drupal\responsive_image\Entity\ResponsiveImageMapping; /** @@ -151,7 +152,7 @@ function theme_responsive_image_formatter($variables) { $path = $variables['path']['path']; $options = isset($variables['path']['options']) ? $variables['path']['options'] : array(); $options['html'] = TRUE; - return _l($responsive_image, $path, $options); + return \Drupal::l($responsive_image, Url::fromUri($path, $options)); } return drupal_render($responsive_image); diff --git a/core/modules/system/src/Tests/Common/UrlTest.php b/core/modules/system/src/Tests/Common/UrlTest.php index e01a7da0c54..92342d2cc06 100644 --- a/core/modules/system/src/Tests/Common/UrlTest.php +++ b/core/modules/system/src/Tests/Common/UrlTest.php @@ -134,11 +134,11 @@ class UrlTest extends WebTestBase { */ function testLinkRenderArrayText() { // Build a link with _l() for reference. - $l = _l('foo', 'http://drupal.org'); + $l = \Drupal::l('foo', Url::fromUri('http://drupal.org')); // Test a renderable array passed to _l(). $renderable_text = array('#markup' => 'foo'); - $l_renderable_text = _l($renderable_text, 'http://drupal.org'); + $l_renderable_text = \Drupal::l($renderable_text, Url::fromUri('http://drupal.org')); $this->assertEqual($l_renderable_text, $l); // Test a themed link with plain text 'text'. diff --git a/core/modules/update/src/Form/UpdateManagerUpdate.php b/core/modules/update/src/Form/UpdateManagerUpdate.php index 88858a60075..8204180e73e 100644 --- a/core/modules/update/src/Form/UpdateManagerUpdate.php +++ b/core/modules/update/src/Form/UpdateManagerUpdate.php @@ -12,6 +12,7 @@ use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Form\FormBase; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\State\StateInterface; +use Drupal\Core\Url; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -111,7 +112,7 @@ class UpdateManagerUpdate extends FormBase { // The project name to display can vary based on the info we have. if (!empty($project['title'])) { if (!empty($project['link'])) { - $project_name = _l($project['title'], $project['link']); + $project_name = $this->l($project['title'], Url::fromUri($project['link'])); } else { $project_name = String::checkPlain($project['title']); @@ -134,7 +135,7 @@ class UpdateManagerUpdate extends FormBase { } $recommended_release = $project['releases'][$project['recommended']]; - $recommended_version = $recommended_release['version'] . ' ' . _l($this->t('(Release notes)'), $recommended_release['release_link'], array('attributes' => array('title' => $this->t('Release notes for @project_title', array('@project_title' => $project['title']))))); + $recommended_version = $recommended_release['version'] . ' ' . $this->l($this->t('(Release notes)'), Url::fromUri($recommended_release['release_link'], array('attributes' => array('title' => $this->t('Release notes for @project_title', array('@project_title' => $project['title'])))))); if ($recommended_release['version_major'] != $project['existing_major']) { $recommended_version .= '
' . $this->t('This update is a major version update which means that it may not be backwards compatible with your currently running version. It is recommended that you read the release notes and proceed at your own risk.') . '
'; } diff --git a/core/modules/update/src/Tests/UpdateContribTest.php b/core/modules/update/src/Tests/UpdateContribTest.php index 35d25a12811..95e2b8899d1 100644 --- a/core/modules/update/src/Tests/UpdateContribTest.php +++ b/core/modules/update/src/Tests/UpdateContribTest.php @@ -7,6 +7,7 @@ namespace Drupal\update\Tests; +use Drupal\Core\Url; use Drupal\Core\Utility\ProjectInfo; /** @@ -50,12 +51,12 @@ class UpdateContribTest extends UpdateTestBase { // Cannot use $this->standardTests() because we need to check for the // 'No available releases found' string. $this->assertRaw('

' . t('Drupal core') . '

'); - $this->assertRaw(_l(t('Drupal'), 'http://example.com/project/drupal')); + $this->assertRaw(\Drupal::l(t('Drupal'), Url::fromUri('http://example.com/project/drupal'))); $this->assertText(t('Up to date')); $this->assertRaw('

' . t('Modules') . '

'); $this->assertNoText(t('Update available')); $this->assertText(t('No available releases found')); - $this->assertNoRaw(_l(t('AAA Update test'), 'http://example.com/project/aaa_update_test')); + $this->assertNoRaw(\Drupal::l(t('AAA Update test'), Url::fromUri('http://example.com/project/aaa_update_test'))); $available = update_get_available(); $this->assertFalse(isset($available['aaa_update_test']['fetch_status']), 'Results are cached even if no releases are available.'); @@ -86,7 +87,7 @@ class UpdateContribTest extends UpdateTestBase { $this->assertText(t('Up to date')); $this->assertRaw('

' . t('Modules') . '

'); $this->assertNoText(t('Update available')); - $this->assertRaw(_l(t('AAA Update test'), 'http://example.com/project/aaa_update_test'), 'Link to aaa_update_test project appears.'); + $this->assertRaw(\Drupal::l(t('AAA Update test'), Url::fromUri('http://example.com/project/aaa_update_test')), 'Link to aaa_update_test project appears.'); } /** @@ -147,10 +148,10 @@ class UpdateContribTest extends UpdateTestBase { $this->assertText(t('CCC Update test')); // We want aaa_update_test included in the ccc_update_test project, not as // its own project on the report. - $this->assertNoRaw(_l(t('AAA Update test'), 'http://example.com/project/aaa_update_test'), 'Link to aaa_update_test project does not appear.'); + $this->assertNoRaw(\Drupal::l(t('AAA Update test'), Url::fromUri('http://example.com/project/aaa_update_test')), 'Link to aaa_update_test project does not appear.'); // The other two should be listed as projects. - $this->assertRaw(_l(t('BBB Update test'), 'http://example.com/project/bbb_update_test'), 'Link to bbb_update_test project appears.'); - $this->assertRaw(_l(t('CCC Update test'), 'http://example.com/project/ccc_update_test'), 'Link to bbb_update_test project appears.'); + $this->assertRaw(\Drupal::l(t('BBB Update test'), Url::fromUri('http://example.com/project/bbb_update_test')), 'Link to bbb_update_test project appears.'); + $this->assertRaw(\Drupal::l(t('CCC Update test'), Url::fromUri('http://example.com/project/ccc_update_test')), 'Link to bbb_update_test project appears.'); // We want to make sure we see the BBB project before the CCC project. // Instead of just searching for 'BBB Update test' or something, we want @@ -197,7 +198,7 @@ class UpdateContribTest extends UpdateTestBase { ); $this->refreshUpdateStatus($xml_mapping); $this->assertText(t('Security update required!')); - $this->assertRaw(_l(t('Update test base theme'), 'http://example.com/project/update_test_basetheme'), 'Link to the Update test base theme project appears.'); + $this->assertRaw(\Drupal::l(t('Update test base theme'), Url::fromUri('http://example.com/project/update_test_basetheme')), 'Link to the Update test base theme project appears.'); } /** @@ -247,8 +248,8 @@ class UpdateContribTest extends UpdateTestBase { 'update_test_subtheme' => '1_0', 'update_test_basetheme' => '1_1-sec', ); - $base_theme_project_link = _l(t('Update test base theme'), 'http://example.com/project/update_test_basetheme'); - $sub_theme_project_link = _l(t('Update test subtheme'), 'http://example.com/project/update_test_subtheme'); + $base_theme_project_link = \Drupal::l(t('Update test base theme'), Url::fromUri('http://example.com/project/update_test_basetheme')); + $sub_theme_project_link = \Drupal::l(t('Update test subtheme'), Url::fromUri('http://example.com/project/update_test_subtheme')); foreach (array(TRUE, FALSE) as $check_disabled) { $update_settings->set('check.disabled_extensions', $check_disabled)->save(); $this->refreshUpdateStatus($xml_mapping); @@ -350,9 +351,9 @@ class UpdateContribTest extends UpdateTestBase { $this->assertUniqueText(t('Failed to get available update data for one project.')); // The other two should be listed as projects. - $this->assertRaw(_l(t('AAA Update test'), 'http://example.com/project/aaa_update_test'), 'Link to aaa_update_test project appears.'); - $this->assertNoRaw(_l(t('BBB Update test'), 'http://example.com/project/bbb_update_test'), 'Link to bbb_update_test project does not appear.'); - $this->assertRaw(_l(t('CCC Update test'), 'http://example.com/project/ccc_update_test'), 'Link to bbb_update_test project appears.'); + $this->assertRaw(\Drupal::l(t('AAA Update test'), Url::fromUri('http://example.com/project/aaa_update_test')), 'Link to aaa_update_test project appears.'); + $this->assertNoRaw(\Drupal::l(t('BBB Update test'), Url::fromUri('http://example.com/project/bbb_update_test')), 'Link to bbb_update_test project does not appear.'); + $this->assertRaw(\Drupal::l(t('CCC Update test'), Url::fromUri('http://example.com/project/ccc_update_test')), 'Link to bbb_update_test project appears.'); } /** @@ -394,7 +395,7 @@ class UpdateContribTest extends UpdateTestBase { $this->drupalGet('admin/reports/updates'); $this->assertRaw('

' . t('Modules') . '

'); $this->assertText(t('Security update required!')); - $this->assertRaw(_l(t('AAA Update test'), 'http://example.com/project/aaa_update_test'), 'Link to aaa_update_test project appears.'); + $this->assertRaw(\Drupal::l(t('AAA Update test'), Url::fromUri('http://example.com/project/aaa_update_test')), 'Link to aaa_update_test project appears.'); // Visit the reports page again without the altering and make sure the // status is back to normal. @@ -402,7 +403,7 @@ class UpdateContribTest extends UpdateTestBase { $this->drupalGet('admin/reports/updates'); $this->assertRaw('

' . t('Modules') . '

'); $this->assertNoText(t('Security update required!')); - $this->assertRaw(_l(t('AAA Update test'), 'http://example.com/project/aaa_update_test'), 'Link to aaa_update_test project appears.'); + $this->assertRaw(\Drupal::l(t('AAA Update test'), Url::fromUri('http://example.com/project/aaa_update_test')), 'Link to aaa_update_test project appears.'); // Turn the altering back on and visit the Update manager UI. $update_test_config->set('update_status', $update_status)->save(); diff --git a/core/modules/update/src/Tests/UpdateCoreTest.php b/core/modules/update/src/Tests/UpdateCoreTest.php index 9000b43ff52..ed6637172a7 100644 --- a/core/modules/update/src/Tests/UpdateCoreTest.php +++ b/core/modules/update/src/Tests/UpdateCoreTest.php @@ -7,6 +7,8 @@ namespace Drupal\update\Tests; +use Drupal\Core\Url; + /** * Tests the Update Manager module through a series of functional tests using * mock XML data. @@ -72,9 +74,9 @@ class UpdateCoreTest extends UpdateTestBase { $this->standardTests(); $this->drupalGet('admin/reports/updates/check'); $this->assertNoText(t('Security update required!')); - $this->assertRaw(_l("8.$minor_version.1" . $extra_version, "http://example.com/drupal-8-$minor_version-1$extra_version-release"), 'Link to release appears.'); - $this->assertRaw(_l(t('Download'), "http://example.com/drupal-8-$minor_version-1$extra_version.tar.gz"), 'Link to download appears.'); - $this->assertRaw(_l(t('Release notes'), "http://example.com/drupal-8-$minor_version-1$extra_version-release"), 'Link to release notes appears.'); + $this->assertRaw(\Drupal::l("8.$minor_version.1" . $extra_version, Url::fromUri("http://example.com/drupal-8-$minor_version-1$extra_version-release")), 'Link to release appears.'); + $this->assertRaw(\Drupal::l(t('Download'), Url::fromUri("http://example.com/drupal-8-$minor_version-1$extra_version.tar.gz")), 'Link to download appears.'); + $this->assertRaw(\Drupal::l(t('Release notes'), Url::fromUri("http://example.com/drupal-8-$minor_version-1$extra_version-release")), 'Link to release notes appears.'); switch ($minor_version) { case 0: @@ -130,9 +132,9 @@ class UpdateCoreTest extends UpdateTestBase { $this->standardTests(); $this->drupalGet('admin/reports/updates/check'); $this->assertNoText(t('Security update required!')); - $this->assertRaw(_l('9.0.0', "http://example.com/drupal-9-0-0-release"), 'Link to release appears.'); - $this->assertRaw(_l(t('Download'), "http://example.com/drupal-9-0-0.tar.gz"), 'Link to download appears.'); - $this->assertRaw(_l(t('Release notes'), "http://example.com/drupal-9-0-0-release"), 'Link to release notes appears.'); + $this->assertRaw(\Drupal::l('9.0.0', Url::fromUri("http://example.com/drupal-9-0-0-release")), 'Link to release appears.'); + $this->assertRaw(\Drupal::l(t('Download'), Url::fromUri("http://example.com/drupal-9-0-0.tar.gz")), 'Link to download appears.'); + $this->assertRaw(\Drupal::l(t('Release notes'), Url::fromUri("http://example.com/drupal-9-0-0-release")), 'Link to release notes appears.'); $this->assertNoText(t('Up to date')); $this->assertText(t('Not supported!')); $this->assertText(t('Recommended version:')); @@ -153,9 +155,9 @@ class UpdateCoreTest extends UpdateTestBase { $this->assertNoText(t('Up to date')); $this->assertNoText(t('Update available')); $this->assertText(t('Security update required!')); - $this->assertRaw(_l("8.$minor_version.2", "http://example.com/drupal-8-$minor_version-2-release"), 'Link to release appears.'); - $this->assertRaw(_l(t('Download'), "http://example.com/drupal-8-$minor_version-2.tar.gz"), 'Link to download appears.'); - $this->assertRaw(_l(t('Release notes'), "http://example.com/drupal-8-$minor_version-2-release"), 'Link to release notes appears.'); + $this->assertRaw(\Drupal::l("8.$minor_version.2", Url::fromUri("http://example.com/drupal-8-$minor_version-2-release")), 'Link to release appears.'); + $this->assertRaw(\Drupal::l(t('Download'), Url::fromUri("http://example.com/drupal-8-$minor_version-2.tar.gz")), 'Link to download appears.'); + $this->assertRaw(\Drupal::l(t('Release notes'), Url::fromUri("http://example.com/drupal-8-$minor_version-2-release")), 'Link to release notes appears.'); } } diff --git a/core/modules/update/src/Tests/UpdateTestBase.php b/core/modules/update/src/Tests/UpdateTestBase.php index 98b768d4771..0025e2145ae 100644 --- a/core/modules/update/src/Tests/UpdateTestBase.php +++ b/core/modules/update/src/Tests/UpdateTestBase.php @@ -21,6 +21,7 @@ namespace Drupal\update\Tests; +use Drupal\Core\Url; use Drupal\simpletest\WebTestBase; /** @@ -55,7 +56,7 @@ abstract class UpdateTestBase extends WebTestBase { */ protected function standardTests() { $this->assertRaw('

' . t('Drupal core') . '

'); - $this->assertRaw(_l(t('Drupal'), 'http://example.com/project/drupal'), 'Link to the Drupal project appears.'); + $this->assertRaw(\Drupal::l(t('Drupal'), Url::fromUri('http://example.com/project/drupal')), 'Link to the Drupal project appears.'); $this->assertNoText(t('No available releases found')); } } diff --git a/core/modules/user/src/Plugin/views/field/LinkEdit.php b/core/modules/user/src/Plugin/views/field/LinkEdit.php index 11f3292e0d6..bb288631be9 100644 --- a/core/modules/user/src/Plugin/views/field/LinkEdit.php +++ b/core/modules/user/src/Plugin/views/field/LinkEdit.php @@ -28,8 +28,7 @@ class LinkEdit extends Link { $text = !empty($this->options['text']) ? $this->options['text'] : $this->t('Edit'); - $this->options['alter']['path'] = $entity->getSystemPath('edit-form'); - $this->options['alter']['query'] = drupal_get_destination(); + $this->options['alter']['url'] = $entity->urlInfo('edit-form', ['query' => ['destination' => drupal_get_destination()]]); return $text; } diff --git a/core/modules/user/src/Tests/UserAdminTest.php b/core/modules/user/src/Tests/UserAdminTest.php index ae5753611b4..900090ca252 100644 --- a/core/modules/user/src/Tests/UserAdminTest.php +++ b/core/modules/user/src/Tests/UserAdminTest.php @@ -52,9 +52,7 @@ class UserAdminTest extends WebTestBase { $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'))); + $link = $user_a->link(t('Edit'), 'edit-form', array('query' => array('destination' => 'admin/people'))); $this->assertRaw($link, 'Found user A edit link on admin users page'); // Test exposed filter elements. diff --git a/core/modules/views/src/Plugin/views/field/FieldPluginBase.php b/core/modules/views/src/Plugin/views/field/FieldPluginBase.php index 6dc4337e54a..eb4372673a9 100644 --- a/core/modules/views/src/Plugin/views/field/FieldPluginBase.php +++ b/core/modules/views/src/Plugin/views/field/FieldPluginBase.php @@ -87,6 +87,13 @@ abstract class FieldPluginBase extends HandlerBase { */ var $additional_fields = array(); + /** + * The link generator. + * + * @var \Drupal\Core\Utility\LinkGeneratorInterface + */ + protected $linkGenerator; + /** * Overrides Drupal\views\Plugin\views\HandlerBase::init(). */ @@ -1345,6 +1352,10 @@ abstract class FieldPluginBase extends HandlerBase { 'absolute' => !empty($alter['absolute']) ? TRUE : FALSE, ); + $alter += [ + 'path' => NULL + ]; + // $path will be run through check_url() by _l() so we do not need to // sanitize it ourselves. $path = $alter['path']; @@ -1376,7 +1387,7 @@ abstract class FieldPluginBase extends HandlerBase { // If the path is empty do not build a link around the given text and return // it as is. // http://www.example.com URLs will not have a $url['path'], so check host as well. - if (empty($url['path']) && empty($url['host']) && empty($url['fragment'])) { + if (empty($url['path']) && empty($url['host']) && empty($url['fragment']) && empty($url['url'])) { return $text; } @@ -1483,7 +1494,12 @@ abstract class FieldPluginBase extends HandlerBase { $options['entity_type'] = $alter['entity_type']; } - $value .= _l($text, $path, $options); + if (isset($options['url']) && $options['url'] instanceof Url) { + $value .= $this->linkGenerator()->generate($text, $options['url']); + } + else { + $value .= _l($text, $path, $options); + } if (!empty($alter['suffix'])) { $value .= Xss::filterAdmin(strtr($alter['suffix'], $tokens)); @@ -1718,6 +1734,17 @@ abstract class FieldPluginBase extends HandlerBase { return $value; } + /** + * Gets the link generator. + * + * @return \Drupal\Core\Utility\LinkGeneratorInterface + */ + protected function linkGenerator() { + if (!isset($this->linkGenerator)) { + $this->linkGenerator = \Drupal::linkGenerator(); + } + return $this->linkGenerator; + } } /** diff --git a/core/modules/views/src/Plugin/views/field/Links.php b/core/modules/views/src/Plugin/views/field/Links.php index 3438447b9d2..b8f4098dd01 100644 --- a/core/modules/views/src/Plugin/views/field/Links.php +++ b/core/modules/views/src/Plugin/views/field/Links.php @@ -73,15 +73,19 @@ abstract class Links extends FieldPluginBase { } $title = $this->view->field[$field]->last_render_text; $path = ''; + $url = NULL; if (!empty($this->view->field[$field]->options['alter']['path'])) { $path = $this->view->field[$field]->options['alter']['path']; } + elseif (!empty($this->view->field[$field]->options['alter']['url']) && $this->view->field[$field]->options['alter']['url'] instanceof UrlObject) { + $url = $this->view->field[$field]->options['alter']['url']; + } // Make sure that tokens are replaced for this paths as well. $tokens = $this->getRenderTokens(array()); $path = strip_tags(String::decodeEntities(strtr($path, $tokens))); $links[$field] = array( - 'url' => UrlObject::fromUri('base://' . $path), + 'url' => $path ? UrlObject::fromUri('base://' . $path) : $url, 'title' => $title, ); if (!empty($this->options['destination'])) { diff --git a/core/modules/views/src/Tests/Handler/FieldUrlTest.php b/core/modules/views/src/Tests/Handler/FieldUrlTest.php index 8373071314b..fe6d71af308 100644 --- a/core/modules/views/src/Tests/Handler/FieldUrlTest.php +++ b/core/modules/views/src/Tests/Handler/FieldUrlTest.php @@ -7,6 +7,7 @@ namespace Drupal\views\Tests\Handler; +use Drupal\Core\Url; use Drupal\views\Tests\ViewUnitTestBase; use Drupal\views\Views; @@ -70,7 +71,7 @@ class FieldUrlTest extends ViewUnitTestBase { $this->executeView($view); - $this->assertEqual(_l('John', 'John'), $view->field['name']->advancedRender($view->result[0])); + $this->assertEqual(\Drupal::l('John', Url::fromUri('base://John')), $view->field['name']->advancedRender($view->result[0])); } } diff --git a/core/modules/views_ui/src/Form/Ajax/Rearrange.php b/core/modules/views_ui/src/Form/Ajax/Rearrange.php index 42fda54a697..e72af89978a 100644 --- a/core/modules/views_ui/src/Form/Ajax/Rearrange.php +++ b/core/modules/views_ui/src/Form/Ajax/Rearrange.php @@ -8,6 +8,7 @@ namespace Drupal\views_ui\Form\Ajax; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Url; use Drupal\views\ViewStorageInterface; use Drupal\views\ViewExecutable; @@ -124,7 +125,7 @@ class Rearrange extends ViewsFormBase { '#id' => 'views-removed-' . $id, '#attributes' => array('class' => array('views-remove-checkbox')), '#default_value' => 0, - '#suffix' => _l('' . $this->t('Remove') . '', 'javascript:void()', array('attributes' => array('id' => 'views-remove-link-' . $id, 'class' => array('views-hidden', 'views-button-remove', 'views-remove-link'), 'alt' => $this->t('Remove this item'), 'title' => $this->t('Remove this item')), 'html' => TRUE)), + '#suffix' => \Drupal::l('' . $this->t('Remove') . '', Url::fromRoute('', array('attributes' => array('id' => 'views-remove-link-' . $id, 'class' => array('views-hidden', 'views-button-remove', 'views-remove-link'), 'alt' => $this->t('Remove this item'), 'title' => $this->t('Remove this item')), 'html' => TRUE))), ); } diff --git a/core/modules/views_ui/src/ViewListBuilder.php b/core/modules/views_ui/src/ViewListBuilder.php index c8dcbe105df..b29d9b0c14e 100644 --- a/core/modules/views_ui/src/ViewListBuilder.php +++ b/core/modules/views_ui/src/ViewListBuilder.php @@ -14,6 +14,7 @@ use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Config\Entity\ConfigEntityListBuilder; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Entity\EntityTypeInterface; +use Drupal\Core\Url; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -263,7 +264,7 @@ class ViewListBuilder extends ConfigEntityListBuilder { if ($display->hasPath()) { $path = $display->getPath(); if ($view->status() && strpos($path, '%') === FALSE) { - $all_paths[] = _l('/' . $path, $path); + $all_paths[] = \Drupal::l('/' . $path, Url::fromUri('base://' . $path)); } else { $all_paths[] = String::checkPlain('/' . $path); diff --git a/core/modules/views_ui/src/ViewUI.php b/core/modules/views_ui/src/ViewUI.php index 5c5786d6549..75c309c2bd5 100644 --- a/core/modules/views_ui/src/ViewUI.php +++ b/core/modules/views_ui/src/ViewUI.php @@ -12,6 +12,7 @@ use Drupal\Component\Utility\Html; use Drupal\Component\Utility\Timer; use Drupal\Component\Utility\Xss; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Url; use Drupal\views\Views; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\views\ViewExecutable; @@ -693,7 +694,7 @@ class ViewUI implements ViewStorageInterface { Xss::filterAdmin($this->executable->getTitle()), ); if (isset($path)) { - $path = _l($path, $path); + $path = \Drupal::l($path, Url::fromUri('base://' . $path)); } else { $path = t('This display has no path.'); diff --git a/core/modules/views_ui/views_ui.theme.inc b/core/modules/views_ui/views_ui.theme.inc index 8a55d3fb6cf..e9e97168e65 100644 --- a/core/modules/views_ui/views_ui.theme.inc +++ b/core/modules/views_ui/views_ui.theme.inc @@ -158,7 +158,7 @@ function theme_views_ui_build_group_filter_form($variables) { 'value' => drupal_render($form['group_items'][$group_id]['value']), 'remove' => array( 'data' => array( - '#markup' => drupal_render($form['group_items'][$group_id]['remove']) . _l('' . t('Remove') . '', 'javascript:void()', array('attributes' => array('id' => 'views-remove-link-' . $group_id, 'class' => array('views-hidden', 'views-button-remove', 'views-groups-remove-link', 'views-remove-link'), 'alt' => t('Remove this item'), 'title' => t('Remove this item')), 'html' => true)), + '#markup' => drupal_render($form['group_items'][$group_id]['remove']) . \Drupal::l('' . t('Remove') . '', Url::fromRoute('', array('attributes' => array('id' => 'views-remove-link-' . $group_id, 'class' => array('views-hidden', 'views-button-remove', 'views-groups-remove-link', 'views-remove-link'), 'alt' => t('Remove this item'), 'title' => t('Remove this item')), 'html' => true))), ), ), );