Issue #3047801 by Eduardo Morales, mikelutz, pguillard, nlisgo, sathish.redcrackle, Berdir: Replace all calls to the deprecated Drupal::l() function in Core
parent
7325b7082b
commit
ae248f2e43
|
|
@ -606,17 +606,15 @@ class Drupal {
|
|||
* A GeneratedLink object containing a link to the given route and
|
||||
* parameters and bubbleable metadata.
|
||||
*
|
||||
* @deprecated in drupal:8.0.0 and is removed from drupal:9.0.0. Use
|
||||
* \Drupal\Core\Link::fromTextAndUrl() instead.
|
||||
*
|
||||
* @see https://www.drupal.org/node/2614344
|
||||
* @see \Drupal\Core\Utility\LinkGeneratorInterface::generate()
|
||||
* @see \Drupal\Core\Url
|
||||
*
|
||||
* @deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0.
|
||||
* Use \Drupal\Core\Link instead.
|
||||
* Example:
|
||||
* @code
|
||||
* $link = Link::fromTextAndUrl($text, $url);
|
||||
* @endcode
|
||||
*/
|
||||
public static function l($text, Url $url) {
|
||||
@trigger_error('\Drupal::l() is deprecated in drupal:8.0.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Link::fromTextAndUrl() instead. See https://www.drupal.org/node/2614344', E_USER_DEPRECATED);
|
||||
return static::getContainer()->get('link_generator')->generate($text, $url);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
use Drupal\Core\Database\Database;
|
||||
use Drupal\Core\File\FileSystemInterface;
|
||||
use Drupal\Core\Link;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\Core\Utility\UpdateException;
|
||||
|
||||
|
|
@ -952,7 +953,7 @@ function hook_requirements($phase) {
|
|||
// Test PHP version
|
||||
$requirements['php'] = [
|
||||
'title' => t('PHP'),
|
||||
'value' => ($phase == 'runtime') ? \Drupal::l(phpversion(), new Url('system.php')) : phpversion(),
|
||||
'value' => ($phase == 'runtime') ? Link::fromTextAndUrl(phpversion(), Url::fromRoute('system.php'))->toString() : 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.', ['%version' => DRUPAL_MINIMUM_PHP]);
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Drupal\Core\Render\Element;
|
||||
|
||||
use Drupal\Core\Link as BaseLink;
|
||||
use Drupal\Core\Url as BaseUrl;
|
||||
use Drupal\Component\Utility\NestedArray;
|
||||
|
||||
|
|
@ -78,7 +79,7 @@ class SystemCompactLink extends Link {
|
|||
}
|
||||
|
||||
$options = NestedArray::mergeDeep($element['#url']->getOptions(), $element['#options']);
|
||||
$element['#markup'] = \Drupal::l($element['#title'], $element['#url']->setOptions($options));
|
||||
$element['#markup'] = BaseLink::fromTextAndUrl($element['#title'], $element['#url']->setOptions($options))->toString();
|
||||
|
||||
return $element;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ namespace Drupal\Tests\aggregator\Kernel\Views;
|
|||
|
||||
use Drupal\Component\Utility\Xss;
|
||||
use Drupal\Core\Render\RenderContext;
|
||||
use Drupal\Core\Link;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
|
||||
use Drupal\views\Views;
|
||||
|
|
@ -111,7 +112,7 @@ class IntegrationTest extends ViewsKernelTestBase {
|
|||
// Ensure that the rendering of the linked title works as expected.
|
||||
foreach ($view->result as $row) {
|
||||
$iid = $view->field['iid']->getValue($row);
|
||||
$expected_link = \Drupal::l($items[$iid]->getTitle(), Url::fromUri($items[$iid]->getLink(), ['absolute' => TRUE]));
|
||||
$expected_link = Link::fromTextAndUrl($items[$iid]->getTitle(), Url::fromUri($items[$iid]->getLink(), ['absolute' => TRUE]))->toString();
|
||||
$output = $renderer->executeInRenderContext(new RenderContext(), function () use ($view, $row) {
|
||||
return $view->field['title']->advancedRender($row);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
use Drupal\Component\Utility\Html;
|
||||
use Drupal\Core\Routing\RouteMatchInterface;
|
||||
use Drupal\Core\Link;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\language\ConfigurableLanguageInterface;
|
||||
use Drupal\system\Entity\Menu;
|
||||
|
|
@ -43,7 +44,7 @@ function block_help($route_name, RouteMatchInterface $route_match) {
|
|||
$demo_theme = $route_match->getParameter('theme') ?: \Drupal::config('system.theme')->get('default');
|
||||
$themes = \Drupal::service('theme_handler')->listInfo();
|
||||
$output = '<p>' . t('Block placement is specific to each theme on your site. Changes will not be saved until you click <em>Save blocks</em> at the bottom of the page.') . '</p>';
|
||||
$output .= '<p>' . \Drupal::l(t('Demonstrate block regions (@theme)', ['@theme' => $themes[$demo_theme]->info['name']]), new Url('block.admin_demo', ['theme' => $demo_theme])) . '</p>';
|
||||
$output .= '<p>' . Link::fromTextAndUrl(t('Demonstrate block regions (@theme)', ['@theme' => $themes[$demo_theme]->info['name']]), Url::fromRoute('block.admin_demo', ['theme' => $demo_theme]))->toString() . '</p>';
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
* Provides page callbacks for custom blocks.
|
||||
*/
|
||||
|
||||
use Drupal\Core\Link;
|
||||
use Drupal\Core\Url;
|
||||
|
||||
/**
|
||||
|
|
@ -23,7 +24,7 @@ function template_preprocess_block_content_add_list(&$variables) {
|
|||
$query = \Drupal::request()->query->all();
|
||||
foreach ($variables['content'] as $type) {
|
||||
$variables['types'][$type->id()] = [
|
||||
'link' => \Drupal::l($type->label(), new Url('block_content.add_form', ['block_content_type' => $type->id()], ['query' => $query])),
|
||||
'link' => Link::fromTextAndUrl($type->label(), Url::fromRoute('block_content.add_form', ['block_content_type' => $type->id()], ['query' => $query]))->toString(),
|
||||
'description' => [
|
||||
'#markup' => $type->getDescription(),
|
||||
],
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Drupal\Tests\book\Functional;
|
||||
|
||||
use Drupal\Core\Link;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\Component\Render\FormattableMarkup;
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
|
|
@ -106,14 +107,14 @@ trait BookTestTrait {
|
|||
$url = $previous->toUrl();
|
||||
$url->setOptions(['attributes' => ['rel' => ['prev'], 'title' => t('Go to previous page')]]);
|
||||
$text = new FormattableMarkup('<b>‹</b> @label', ['@label' => $previous->label()]);
|
||||
$this->assertRaw(\Drupal::l($text, $url), 'Previous page link found.');
|
||||
$this->assertRaw(Link::fromTextAndUrl($text, $url)->toString(), 'Previous page link found.');
|
||||
}
|
||||
|
||||
if ($up) {
|
||||
/** @var \Drupal\Core\Url $url */
|
||||
$url = $up->toUrl();
|
||||
$url->setOptions(['attributes' => ['title' => t('Go to parent page')]]);
|
||||
$this->assertRaw(\Drupal::l('Up', $url), 'Up page link found.');
|
||||
$this->assertRaw(Link::fromTextAndUrl('Up', $url)->toString(), 'Up page link found.');
|
||||
}
|
||||
|
||||
if ($next) {
|
||||
|
|
@ -121,7 +122,7 @@ trait BookTestTrait {
|
|||
$url = $next->toUrl();
|
||||
$url->setOptions(['attributes' => ['rel' => ['next'], 'title' => t('Go to next page')]]);
|
||||
$text = new FormattableMarkup('@label <b>›</b>', ['@label' => $next->label()]);
|
||||
$this->assertRaw(\Drupal::l($text, $url), 'Next page link found.');
|
||||
$this->assertRaw(Link::fromTextAndUrl($text, $url)->toString(), 'Next page link found.');
|
||||
}
|
||||
|
||||
// Compute the expected breadcrumb.
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ use Drupal\Core\Form\FormStateInterface;
|
|||
use Drupal\Core\Routing\RouteMatchInterface;
|
||||
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
|
||||
use Drupal\Core\Render\Element;
|
||||
use Drupal\Core\Link;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\field\FieldConfigInterface;
|
||||
use Drupal\field\FieldStorageConfigInterface;
|
||||
|
|
@ -678,17 +679,17 @@ function template_preprocess_comment(&$variables) {
|
|||
}
|
||||
|
||||
if (isset($comment->in_preview)) {
|
||||
$variables['title'] = \Drupal::l($comment->getSubject(), new Url('<front>'));
|
||||
$variables['permalink'] = \Drupal::l(t('Permalink'), new Url('<front>'));
|
||||
$variables['title'] = Link::fromTextAndUrl($comment->getSubject(), Url::fromRoute('<front>'))->toString();
|
||||
$variables['permalink'] = Link::fromTextAndUrl(t('Permalink'), Url::fromRoute('<front>'))->toString();
|
||||
}
|
||||
else {
|
||||
$uri = $comment->permalink();
|
||||
$attributes = $uri->getOption('attributes') ?: [];
|
||||
$attributes += ['class' => ['permalink'], 'rel' => 'bookmark'];
|
||||
$uri->setOption('attributes', $attributes);
|
||||
$variables['title'] = \Drupal::l($comment->getSubject(), $uri);
|
||||
$variables['title'] = Link::fromTextAndUrl($comment->getSubject(), $uri)->toString();
|
||||
|
||||
$variables['permalink'] = \Drupal::l(t('Permalink'), $comment->permalink());
|
||||
$variables['permalink'] = Link::fromTextAndUrl(t('Permalink'), $comment->permalink())->toString();
|
||||
}
|
||||
|
||||
$variables['submitted'] = t('Submitted by @username on @datetime', ['@username' => $variables['author'], '@datetime' => $variables['created']]);
|
||||
|
|
@ -715,8 +716,8 @@ function template_preprocess_comment(&$variables) {
|
|||
$attributes = $permalink_uri_parent->getOption('attributes') ?: [];
|
||||
$attributes += ['class' => ['permalink'], 'rel' => 'bookmark'];
|
||||
$permalink_uri_parent->setOption('attributes', $attributes);
|
||||
$variables['parent_title'] = \Drupal::l($comment_parent->getSubject(), $permalink_uri_parent);
|
||||
$variables['parent_permalink'] = \Drupal::l(t('Parent permalink'), $permalink_uri_parent);
|
||||
$variables['parent_title'] = Link::fromTextAndUrl($comment_parent->getSubject(), $permalink_uri_parent)->toString();
|
||||
$variables['parent_permalink'] = Link::fromTextAndUrl(t('Parent permalink'), $permalink_uri_parent)->toString();
|
||||
$variables['parent'] = t('In reply to @parent_title by @parent_username',
|
||||
['@parent_username' => $variables['parent_author'], '@parent_title' => $variables['parent_title']]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ namespace Drupal\Tests\comment\Kernel\Views;
|
|||
|
||||
use Drupal\comment\CommentManagerInterface;
|
||||
use Drupal\Core\Session\AnonymousUserSession;
|
||||
use Drupal\Core\Link;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\entity_test\Entity\EntityTest;
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
|
|
@ -81,7 +82,7 @@ class CommentLinksTest extends CommentViewsKernelTestBase {
|
|||
$approve_comment = $view->style_plugin->getField(0, 'approve_comment');
|
||||
$options = ['query' => ['destination' => '/']];
|
||||
$url = Url::fromRoute('comment.approve', ['comment' => $comment->id()], $options);
|
||||
$this->assertEqual(\Drupal::l('Approve', $url), (string) $approve_comment, 'Found a comment approve link for an unapproved comment.');
|
||||
$this->assertEqual(Link::fromTextAndUrl('Approve', $url)->toString(), (string) $approve_comment, 'Found a comment approve link for an unapproved comment.');
|
||||
|
||||
// Approve the comment.
|
||||
$comment->setPublished();
|
||||
|
|
@ -181,7 +182,7 @@ class CommentLinksTest extends CommentViewsKernelTestBase {
|
|||
'field_name' => 'comment',
|
||||
'pid' => $comment->id(),
|
||||
]);
|
||||
$this->assertEqual(\Drupal::l('Reply', $url), (string) $replyto_comment, 'Found the comment reply link as an admin user.');
|
||||
$this->assertEqual(Link::fromTextAndUrl('Reply', $url)->toString(), (string) $replyto_comment, 'Found the comment reply link as an admin user.');
|
||||
|
||||
// Check if I can see the reply link as an anonymous user.
|
||||
$account_switcher->switchTo(new AnonymousUserSession());
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ use Drupal\Component\Utility\Html;
|
|||
use Drupal\Component\Utility\Unicode;
|
||||
use Drupal\Core\Database\Database;
|
||||
use Drupal\Core\Logger\RfcLogLevel;
|
||||
use Drupal\Core\Link;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\dblog\Controller\DbLogController;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
|
@ -307,7 +308,7 @@ class DbLogTest extends BrowserTestBase {
|
|||
* page.
|
||||
*/
|
||||
private function verifyLinkEscaping() {
|
||||
$link = \Drupal::l('View', Url::fromRoute('entity.node.canonical', ['node' => 1]));
|
||||
$link = Link::fromTextAndUrl('View', Url::fromRoute('entity.node.canonical', ['node' => 1]))->toString();
|
||||
$message = 'Log entry added to do the verifyLinkEscaping test.';
|
||||
$this->generateLogEntries(1, [
|
||||
'message' => $message,
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ namespace Drupal\Tests\dblog\Kernel\Views;
|
|||
use Drupal\Component\Render\FormattableMarkup;
|
||||
use Drupal\Component\Utility\Xss;
|
||||
use Drupal\Core\Logger\RfcLogLevel;
|
||||
use Drupal\Core\Link;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
|
||||
use Drupal\views\Views;
|
||||
|
|
@ -177,12 +178,15 @@ class ViewsIntegrationTest extends ViewsKernelTestBase {
|
|||
// Setup a watchdog entry without tokens.
|
||||
$entries[] = [
|
||||
'message' => $this->randomMachineName(),
|
||||
'variables' => ['link' => \Drupal::l('Link', new Url('<front>'))],
|
||||
'variables' => ['link' => Link::fromTextAndUrl('Link', Url::fromRoute('<front>'))->toString()],
|
||||
];
|
||||
// Setup a watchdog entry with one token.
|
||||
$entries[] = [
|
||||
'message' => '@token1',
|
||||
'variables' => ['@token1' => $this->randomMachineName(), 'link' => \Drupal::l('Link', new Url('<front>'))],
|
||||
'variables' => [
|
||||
'@token1' => $this->randomMachineName(),
|
||||
'link' => Link::fromTextAndUrl('Link', Url::fromRoute('<front>'))->toString(),
|
||||
],
|
||||
];
|
||||
// Setup a watchdog entry with two tokens.
|
||||
$entries[] = [
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ use Drupal\field\FieldConfigInterface;
|
|||
use Drupal\field\FieldStorageConfigInterface;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Routing\RouteMatchInterface;
|
||||
use Drupal\Core\Link;
|
||||
use Drupal\Core\Url;
|
||||
|
||||
/*
|
||||
|
|
@ -111,7 +112,7 @@ function field_help($route_name, RouteMatchInterface $route_match) {
|
|||
if (isset($modules[$provider])) {
|
||||
$display = \Drupal::moduleHandler()->getName($provider);
|
||||
if (\Drupal::moduleHandler()->implementsHook($provider, 'help')) {
|
||||
$items[] = \Drupal::l($display, new Url('help.page', ['name' => $provider]));
|
||||
$items[] = Link::fromTextAndUrl($display, Url::fromRoute('help.page', ['name' => $provider]))->toRenderable();
|
||||
}
|
||||
else {
|
||||
$items[] = $display;
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ use Drupal\Core\Entity\EntityTypeInterface;
|
|||
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
|
||||
use Drupal\Core\Field\FieldTypePluginManagerInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Drupal\Core\Link;
|
||||
|
||||
/**
|
||||
* Defines a class to build a listing of fields.
|
||||
|
|
@ -122,7 +123,7 @@ class FieldStorageConfigListBuilder extends ConfigEntityListBuilder {
|
|||
$usage = [];
|
||||
foreach ($field_storage->getBundles() as $bundle) {
|
||||
if ($route_info = FieldUI::getOverviewRouteInfo($entity_type_id, $bundle)) {
|
||||
$usage[] = \Drupal::l($this->bundles[$entity_type_id][$bundle]['label'], $route_info);
|
||||
$usage[] = Link::fromTextAndUrl($this->bundles[$entity_type_id][$bundle]['label'], $route_info)->toRenderable();
|
||||
}
|
||||
else {
|
||||
$usage[] = $this->bundles[$entity_type_id][$bundle]['label'];
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ use Drupal\Core\Messenger\MessengerInterface;
|
|||
use Drupal\Core\Render\BubbleableMetadata;
|
||||
use Drupal\Core\Render\Element;
|
||||
use Drupal\Core\Routing\RouteMatchInterface;
|
||||
use Drupal\Core\Link;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\file\Entity\File;
|
||||
use Drupal\file\FileInterface;
|
||||
|
|
@ -1504,7 +1505,7 @@ function template_preprocess_file_link(&$variables) {
|
|||
$variables['attributes']->addClass($classes);
|
||||
$variables['file_size'] = format_size($file->getSize());
|
||||
|
||||
$variables['link'] = \Drupal::l($link_text, Url::fromUri($url, $options));
|
||||
$variables['link'] = Link::fromTextAndUrl($link_text, Url::fromUri($url, $options))->toString();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ use Drupal\comment\CommentInterface;
|
|||
use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
use Drupal\Core\Link;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Routing\RouteMatchInterface;
|
||||
|
|
@ -446,11 +447,11 @@ function template_preprocess_forums(&$variables) {
|
|||
if ($variables['tid'] != $topic->forum_tid) {
|
||||
$variables['topics'][$id]->moved = TRUE;
|
||||
$variables['topics'][$id]->title = $topic->getTitle();
|
||||
$variables['topics'][$id]->message = \Drupal::l(t('This topic has been moved'), new Url('forum.page', ['taxonomy_term' => $topic->forum_tid]));
|
||||
$variables['topics'][$id]->message = Link::fromTextAndUrl(t('This topic has been moved'), Url::fromRoute('forum.page', ['taxonomy_term' => $topic->forum_tid]))->toString();
|
||||
}
|
||||
else {
|
||||
$variables['topics'][$id]->moved = FALSE;
|
||||
$variables['topics'][$id]->title_link = \Drupal::l($topic->getTitle(), $topic->toUrl());
|
||||
$variables['topics'][$id]->title_link = Link::fromTextAndUrl($topic->getTitle(), $topic->toUrl())->toString();
|
||||
$variables['topics'][$id]->message = '';
|
||||
}
|
||||
$forum_submitted = [
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
* Defines simple link field types.
|
||||
*/
|
||||
|
||||
use Drupal\Core\Link;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\Core\Routing\RouteMatchInterface;
|
||||
|
||||
|
|
@ -62,5 +63,5 @@ function link_theme() {
|
|||
* - url: A \Drupal\Core\Url object.
|
||||
*/
|
||||
function template_preprocess_link_formatter_link_separate(&$variables) {
|
||||
$variables['link'] = \Drupal::l($variables['url_title'], $variables['url']);
|
||||
$variables['link'] = Link::fromTextAndUrl($variables['url_title'], $variables['url'])->toString();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ namespace Drupal\Tests\link\Functional;
|
|||
use Drupal\Component\Utility\Html;
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
use Drupal\Core\Entity\Entity\EntityViewDisplay;
|
||||
use Drupal\Core\Link;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\entity_test\Entity\EntityTest;
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
|
|
@ -342,7 +343,7 @@ class LinkFieldTest extends BrowserTestBase {
|
|||
$this->assertText(t('entity_test @id has been created.', ['@id' => $id]));
|
||||
|
||||
$output = $this->renderTestEntity($id);
|
||||
$expected_link = (string) \Drupal::l($value, Url::fromUri($value));
|
||||
$expected_link = (string) Link::fromTextAndUrl($value, Url::fromUri($value))->toString();
|
||||
$this->assertContains($expected_link, $output);
|
||||
|
||||
// Verify that a link with text is rendered using the link text.
|
||||
|
|
@ -354,7 +355,7 @@ class LinkFieldTest extends BrowserTestBase {
|
|||
$this->assertText(t('entity_test @id has been updated.', ['@id' => $id]));
|
||||
|
||||
$output = $this->renderTestEntity($id);
|
||||
$expected_link = (string) \Drupal::l($title, Url::fromUri($value));
|
||||
$expected_link = (string) Link::fromTextAndUrl($title, Url::fromUri($value))->toString();
|
||||
$this->assertContains($expected_link, $output);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
use Drupal\Core\File\Exception\FileException;
|
||||
use Drupal\Core\File\FileSystemInterface;
|
||||
use Drupal\Core\Link;
|
||||
use Drupal\Core\Url;
|
||||
|
||||
/**
|
||||
|
|
@ -272,7 +273,7 @@ function locale_requirements($phase) {
|
|||
if ($available_updates) {
|
||||
$requirements['locale_translation'] = [
|
||||
'title' => t('Translation update status'),
|
||||
'value' => \Drupal::l(t('Updates available'), new Url('locale.translate_status')),
|
||||
'value' => Link::fromTextAndUrl(t('Updates available'), Url::fromRoute('locale.translate_status'))->toString(),
|
||||
'severity' => REQUIREMENT_WARNING,
|
||||
'description' => t('Updates available for: @languages. See the <a href=":updates">Available translation updates</a> page for more information.', ['@languages' => implode(', ', $available_updates), ':updates' => Url::fromRoute('locale.translate_status')->toString()]),
|
||||
];
|
||||
|
|
@ -297,7 +298,7 @@ function locale_requirements($phase) {
|
|||
else {
|
||||
$requirements['locale_translation'] = [
|
||||
'title' => t('Translation update status'),
|
||||
'value' => \Drupal::l(t('Can not determine status'), new Url('locale.translate_status')),
|
||||
'value' => Link::fromTextAndUrl(t('Can not determine status'), Url::fromRoute('locale.translate_status'))->toString(),
|
||||
'severity' => REQUIREMENT_WARNING,
|
||||
'description' => t('No translation status is available. See the <a href=":updates">Available translation updates</a> page for more information.', [':updates' => Url::fromRoute('locale.translate_status')->toString()]),
|
||||
];
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ use Drupal\Component\Utility\UrlHelper;
|
|||
use Drupal\Component\Utility\Xss;
|
||||
use Drupal\Core\File\Exception\FileException;
|
||||
use Drupal\Core\File\FileSystemInterface;
|
||||
use Drupal\Core\Link;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\Core\Asset\AttachedAssetsInterface;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
|
|
@ -647,16 +648,14 @@ function locale_form_language_admin_overview_form_alter(&$form, FormStateInterfa
|
|||
'ratio' => 0,
|
||||
];
|
||||
if (!$language->isLocked() && locale_is_translatable($langcode)) {
|
||||
$form['languages'][$langcode]['locale_statistics'] = [
|
||||
'#markup' => \Drupal::l(
|
||||
t('@translated/@total (@ratio%)', [
|
||||
'@translated' => $stats[$langcode]['translated'],
|
||||
'@total' => $total_strings,
|
||||
'@ratio' => $stats[$langcode]['ratio'],
|
||||
]),
|
||||
new Url('locale.translate_page', [], ['query' => ['langcode' => $langcode]])
|
||||
),
|
||||
];
|
||||
$form['languages'][$langcode]['locale_statistics'] = Link::fromTextAndUrl(
|
||||
t('@translated/@total (@ratio%)', [
|
||||
'@translated' => $stats[$langcode]['translated'],
|
||||
'@total' => $total_strings,
|
||||
'@ratio' => $stats[$langcode]['ratio'],
|
||||
]),
|
||||
Url::fromRoute('locale.translate_page', [], ['query' => ['langcode' => $langcode]])
|
||||
)->toRenderable();
|
||||
}
|
||||
else {
|
||||
$form['languages'][$langcode]['locale_statistics'] = [
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
* Interface translation summary, editing and deletion user interfaces.
|
||||
*/
|
||||
|
||||
use Drupal\Core\Link;
|
||||
use Drupal\Core\Url;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
|
||||
|
|
@ -77,5 +78,5 @@ function template_preprocess_locale_translation_last_check(array &$variables) {
|
|||
$last = $variables['last'];
|
||||
$variables['last_checked'] = ($last != NULL);
|
||||
$variables['time'] = \Drupal::service('date.formatter')->formatTimeDiffSince($last);
|
||||
$variables['link'] = \Drupal::l(t('Check manually'), new Url('locale.check_translation', [], ['query' => \Drupal::destination()->getAsArray()]));
|
||||
$variables['link'] = Link::fromTextAndUrl(t('Check manually'), Url::fromRoute('locale.check_translation', [], ['query' => \Drupal::destination()->getAsArray()]))->toString();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
* Content administration and module settings user interface.
|
||||
*/
|
||||
|
||||
use Drupal\Core\Link;
|
||||
use Drupal\node\NodeInterface;
|
||||
|
||||
/**
|
||||
|
|
@ -134,7 +135,7 @@ function _node_mass_update_batch_process(array $nodes, array $updates, $langcode
|
|||
$node = _node_mass_update_helper($node, $updates, $langcode);
|
||||
|
||||
// Store result for post-processing in the finished callback.
|
||||
$context['results'][] = \Drupal::l($node->label(), $node->toUrl());
|
||||
$context['results'][] = Link::fromTextAndUrl($node->label(), $node->toUrl())->toString();
|
||||
|
||||
// Update our progress information.
|
||||
$context['sandbox']['progress']++;
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ use Drupal\Core\Database\Query\SelectInterface;
|
|||
use Drupal\Core\Database\StatementInterface;
|
||||
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Link;
|
||||
use Drupal\Core\Render\Element;
|
||||
use Drupal\Core\Routing\RouteMatchInterface;
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
|
|
@ -226,7 +227,7 @@ function node_title_list(StatementInterface $result, $title = NULL) {
|
|||
// database rows, not actual nodes.
|
||||
$nids[] = $row->nid;
|
||||
$options = !empty($row->comment_count) ? ['attributes' => ['title' => \Drupal::translation()->formatPlural($row->comment_count, '1 comment', '@count comments')]] : [];
|
||||
$items[] = \Drupal::l($row->title, new Url('entity.node.canonical', ['node' => $row->nid], $options));
|
||||
$items[] = Link::fromTextAndUrl($row->title, Url::fromRoute('entity.node.canonical', ['node' => $row->nid], $options))->toString();
|
||||
$num_rows = TRUE;
|
||||
}
|
||||
|
||||
|
|
@ -545,7 +546,7 @@ function template_preprocess_node_add_list(&$variables) {
|
|||
foreach ($variables['content'] as $type) {
|
||||
$variables['types'][$type->id()] = [
|
||||
'type' => $type->id(),
|
||||
'add_link' => \Drupal::l($type->label(), new Url('node.add', ['node_type' => $type->id()])),
|
||||
'add_link' => Link::fromTextAndUrl($type->label(), Url::fromRoute('node.add', ['node_type' => $type->id()]))->toString(),
|
||||
'description' => [
|
||||
'#markup' => $type->getDescription(),
|
||||
],
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Drupal\Tests\node\Functional;
|
||||
|
||||
use Drupal\Core\Link;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\node\Entity\Node;
|
||||
use Drupal\node\Entity\NodeType;
|
||||
|
|
@ -114,7 +115,7 @@ class NodeRevisionsUiTest extends NodeTestBase {
|
|||
// Assert the old revision message.
|
||||
$date = $this->container->get('date.formatter')->format($nodes[0]->revision_timestamp->value, 'short');
|
||||
$url = new Url('entity.node.revision', ['node' => $nodes[0]->id(), 'node_revision' => $nodes[0]->getRevisionId()]);
|
||||
$this->assertRaw(\Drupal::l($date, $url) . ' by ' . $editor);
|
||||
$this->assertRaw(Link::fromTextAndUrl($date, $url)->toString() . ' by ' . $editor);
|
||||
|
||||
// Assert the current revision message.
|
||||
$date = $this->container->get('date.formatter')->format($nodes[1]->revision_timestamp->value, 'short');
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
namespace Drupal\Tests\search\Functional;
|
||||
|
||||
use Drupal\Component\Render\FormattableMarkup;
|
||||
use Drupal\Core\Link;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\search\Entity\SearchPage;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
|
@ -48,7 +49,7 @@ class SearchConfigSettingsFormTest extends BrowserTestBase {
|
|||
// 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] = \Drupal::l($node->label(), $node->toUrl()) . ' pizza sandwich';
|
||||
$edit[$body_key] = Link::fromTextAndUrl($node->label(), $node->toUrl())->toString() . ' pizza sandwich';
|
||||
$this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
|
||||
|
||||
$this->container->get('plugin.manager.search')->createInstance('node_search')->updateIndex();
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ namespace Drupal\Tests\search\Functional;
|
|||
use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
|
||||
use Drupal\comment\Tests\CommentTestTrait;
|
||||
use Drupal\Core\Database\Database;
|
||||
use Drupal\Core\Link;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\filter\Entity\FilterFormat;
|
||||
use Drupal\search\Entity\SearchPage;
|
||||
|
|
@ -224,7 +225,7 @@ class SearchRankingTest extends BrowserTestBase {
|
|||
foreach ($shuffled_tags as $tag) {
|
||||
switch ($tag) {
|
||||
case 'a':
|
||||
$settings['body'] = [['value' => \Drupal::l('Drupal Rocks', new Url('<front>')), 'format' => 'full_html']];
|
||||
$settings['body'] = [['value' => Link::fromTextAndUrl('Drupal Rocks', Url::fromRoute('<front>'))->toString(), 'format' => 'full_html']];
|
||||
break;
|
||||
case 'notag':
|
||||
$settings['body'] = [['value' => 'Drupal Rocks']];
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ namespace Drupal\shortcut;
|
|||
|
||||
use Drupal\Core\Entity\ContentEntityForm;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Link;
|
||||
|
||||
/**
|
||||
* Form handler for the shortcut entity forms.
|
||||
|
|
@ -40,7 +41,7 @@ class ShortcutForm extends ContentEntityForm {
|
|||
// 'link to any content', but has no right to access the linked page. So we
|
||||
// check the access before showing the link.
|
||||
if ($url->access()) {
|
||||
$view_link = \Drupal::l($entity->getTitle(), $url);
|
||||
$view_link = Link::fromTextAndUrl($entity->getTitle(), $url)->toString();
|
||||
}
|
||||
else {
|
||||
$view_link = $entity->getTitle();
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
namespace Drupal\Tests\statistics\Functional;
|
||||
|
||||
use Drupal\Core\Cache\Cache;
|
||||
use Drupal\Core\Link;
|
||||
use Drupal\Tests\system\Functional\Cache\AssertPageCacheContextsAndTagsTrait;
|
||||
|
||||
/**
|
||||
|
|
@ -57,7 +58,7 @@ class StatisticsReportsTest extends StatisticsTestBase {
|
|||
$this->assertCacheContexts($contexts);
|
||||
|
||||
// Check if the node link is displayed.
|
||||
$this->assertRaw(\Drupal::l($node->label(), $node->toUrl('canonical')), 'Found link to visited node.');
|
||||
$this->assertRaw(Link::fromTextAndUrl($node->label(), $node->toUrl('canonical'))->toString(), 'Found link to visited node.');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
* Redirects logging messages to syslog.
|
||||
*/
|
||||
|
||||
use Drupal\Core\Link;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Routing\RouteMatchInterface;
|
||||
|
|
@ -34,7 +35,7 @@ function syslog_help($route_name, RouteMatchInterface $route_match) {
|
|||
*/
|
||||
function syslog_form_system_logging_settings_alter(&$form, FormStateInterface $form_state) {
|
||||
$config = \Drupal::configFactory()->getEditable('syslog.settings');
|
||||
$help = \Drupal::moduleHandler()->moduleExists('help') ? ' ' . \Drupal::l(t('More information'), new Url('help.page', ['name' => 'syslog'])) . '.' : NULL;
|
||||
$help = \Drupal::moduleHandler()->moduleExists('help') ? ' ' . Link::fromTextAndUrl(t('More information'), Url::fromRoute('help.page', ['name' => 'syslog']))->toString() . '.' : NULL;
|
||||
$form['syslog_identity'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Syslog identity'),
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
*/
|
||||
|
||||
use Drupal\Component\Utility\Html;
|
||||
use Drupal\Core\Link;
|
||||
use Drupal\Core\Render\Element;
|
||||
use Drupal\Core\Template\Attribute;
|
||||
|
||||
|
|
@ -25,7 +26,7 @@ function template_preprocess_admin_block_content(&$variables) {
|
|||
if (!empty($variables['content'])) {
|
||||
$variables['compact'] = system_admin_compact_mode();
|
||||
foreach ($variables['content'] as $key => $item) {
|
||||
$variables['content'][$key]['link'] = \Drupal::l($item['title'], $item['url']);
|
||||
$variables['content'][$key]['link'] = Link::fromTextAndUrl($item['title'], $item['url'])->toString();
|
||||
if (!$variables['compact'] && isset($item['description'])) {
|
||||
$variables['content'][$key]['description'] = ['#markup' => $item['description']];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ use Drupal\Component\Render\FormattableMarkup;
|
|||
use Drupal\Component\Utility\UrlHelper;
|
||||
use Drupal\Core\Cache\Cache;
|
||||
use Drupal\Core\Language\Language;
|
||||
use Drupal\Core\Link;
|
||||
use Drupal\Core\Render\RenderContext;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
|
@ -27,12 +28,12 @@ class UrlTest extends BrowserTestBase {
|
|||
* Confirms that invalid URLs are filtered in link generating functions.
|
||||
*/
|
||||
public function testLinkXSS() {
|
||||
// Test \Drupal::l().
|
||||
// Test link generator.
|
||||
$text = $this->randomMachineName();
|
||||
$path = "<SCRIPT>alert('XSS')</SCRIPT>";
|
||||
$encoded_path = "3CSCRIPT%3Ealert%28%27XSS%27%29%3C/SCRIPT%3E";
|
||||
|
||||
$link = \Drupal::l($text, Url::fromUserInput('/' . $path));
|
||||
$link = Link::fromTextAndUrl($text, Url::fromUserInput('/' . $path))->toString();
|
||||
$this->assertTrue(strpos($link, $encoded_path) !== FALSE && strpos($link, $path) === FALSE, new FormattableMarkup('XSS attack @path was filtered by \Drupal\Core\Utility\LinkGeneratorInterface::generate().', ['@path' => $path]));
|
||||
|
||||
// Test \Drupal\Core\Url.
|
||||
|
|
@ -139,8 +140,8 @@ class UrlTest extends BrowserTestBase {
|
|||
// \Drupal\Core\Utility\LinkGeneratorInterface::generate() and #type 'link'.
|
||||
// Test the link generator.
|
||||
$class_l = $this->randomMachineName();
|
||||
$link_l = \Drupal::l($this->randomMachineName(), new Url('<current>', [], ['attributes' => ['class' => [$class_l]]]));
|
||||
$this->assertTrue($this->hasAttribute('class', $link_l, $class_l), new FormattableMarkup('Custom class @class is present on link when requested by l()', ['@class' => $class_l]));
|
||||
$link_l = Link::fromTextAndUrl($this->randomMachineName(), Url::fromRoute('<current>', [], ['attributes' => ['class' => [$class_l]]]))->toString();
|
||||
$this->assertTrue($this->hasAttribute('class', $link_l, $class_l), new FormattableMarkup('Custom class @class is present on link when requested by Link::toString()', ['@class' => $class_l]));
|
||||
|
||||
// Test #type.
|
||||
$class_theme = $this->randomMachineName();
|
||||
|
|
@ -166,12 +167,12 @@ class UrlTest extends BrowserTestBase {
|
|||
$renderer = $this->container->get('renderer');
|
||||
|
||||
// Build a link with the link generator for reference.
|
||||
$l = \Drupal::l('foo', Url::fromUri('https://www.drupal.org'));
|
||||
$l = Link::fromTextAndUrl('foo', Url::fromUri('https://www.drupal.org'))->toString();
|
||||
|
||||
// Test a renderable array passed to the link generator.
|
||||
$renderer->executeInRenderContext(new RenderContext(), function () use ($renderer, $l) {
|
||||
$renderable_text = ['#markup' => 'foo'];
|
||||
$l_renderable_text = \Drupal::l($renderable_text, Url::fromUri('https://www.drupal.org'));
|
||||
$l_renderable_text = \Drupal::service('link_generator')->generate($renderable_text, Url::fromUri('https://www.drupal.org'));
|
||||
$this->assertEqual($l_renderable_text, $l);
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Drupal\Tests\taxonomy\Functional;
|
||||
|
||||
use Drupal\Core\Link;
|
||||
use Drupal\Core\Database\Database;
|
||||
use Drupal\Core\Field\FieldStorageDefinitionInterface;
|
||||
|
||||
|
|
@ -213,7 +214,7 @@ class TermIndexTest extends TaxonomyTestBase {
|
|||
$this->drupalGet('taxonomy/term/' . $term1->id());
|
||||
// Breadcrumbs are not rendered with a language, prevent the term
|
||||
// language from being added to the options.
|
||||
$this->assertRaw(\Drupal::l($term2->getName(), $term2->toUrl('canonical', ['language' => NULL])), 'Parent term link is displayed when viewing the node.');
|
||||
$this->assertRaw(Link::fromTextAndUrl($term2->getName(), $term2->toUrl('canonical', ['language' => NULL]))->toString(), 'Parent term link is displayed when viewing the node.');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
* A dummy module to test API interaction with the Toolbar module.
|
||||
*/
|
||||
|
||||
use Drupal\Core\Link;
|
||||
use Drupal\Core\Url;
|
||||
|
||||
/**
|
||||
|
|
@ -33,9 +34,9 @@ function toolbar_test_toolbar() {
|
|||
'content' => [
|
||||
'#theme' => 'item_list',
|
||||
'#items' => [
|
||||
\Drupal::l(t('link 1'), new Url('<front>', [], ['attributes' => ['title' => 'Test link 1 title']])),
|
||||
\Drupal::l(t('link 2'), new Url('<front>', [], ['attributes' => ['title' => 'Test link 2 title']])),
|
||||
\Drupal::l(t('link 3'), new Url('<front>', [], ['attributes' => ['title' => 'Test link 3 title']])),
|
||||
Link::fromTextAndUrl(t('link 1'), Url::fromRoute('<front>', [], ['attributes' => ['title' => 'Test link 1 title']]))->toRenderable(),
|
||||
Link::fromTextAndUrl(t('link 2'), Url::fromRoute('<front>', [], ['attributes' => ['title' => 'Test link 2 title']]))->toRenderable(),
|
||||
Link::fromTextAndUrl(t('link 3'), Url::fromRoute('<front>', [], ['attributes' => ['title' => 'Test link 3 title']]))->toRenderable(),
|
||||
],
|
||||
'#attributes' => [
|
||||
'class' => ['toolbar-menu'],
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ namespace Drupal\update\Tests;
|
|||
@trigger_error(__NAMESPACE__ . '\UpdateTestBase is deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. Instead, use \Drupal\Tests\update\Functional\UpdateTestBase', E_USER_DEPRECATED);
|
||||
|
||||
use Drupal\Core\DrupalKernel;
|
||||
use Drupal\Core\Link;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
|
||||
|
|
@ -81,7 +82,7 @@ abstract class UpdateTestBase extends WebTestBase {
|
|||
*/
|
||||
protected function standardTests() {
|
||||
$this->assertRaw('<h3>' . t('Drupal core') . '</h3>');
|
||||
$this->assertRaw(\Drupal::l(t('Drupal'), Url::fromUri('http://example.com/project/drupal')), 'Link to the Drupal project appears.');
|
||||
$this->assertRaw(Link::fromTextAndUrl(t('Drupal'), Url::fromUri('http://example.com/project/drupal'))->toString(), 'Link to the Drupal project appears.');
|
||||
$this->assertNoText(t('No available releases found'));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Drupal\Tests\update\Functional;
|
||||
|
||||
use Drupal\Core\Link;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\Core\Utility\ProjectInfo;
|
||||
|
||||
|
|
@ -46,12 +47,12 @@ class UpdateContribTest extends UpdateTestBase {
|
|||
// Cannot use $this->standardTests() because we need to check for the
|
||||
// 'No available releases found' string.
|
||||
$this->assertRaw('<h3>' . t('Drupal core') . '</h3>');
|
||||
$this->assertRaw(\Drupal::l(t('Drupal'), Url::fromUri('http://example.com/project/drupal')));
|
||||
$this->assertRaw(Link::fromTextAndUrl(t('Drupal'), Url::fromUri('http://example.com/project/drupal'))->toString());
|
||||
$this->assertText(t('Up to date'));
|
||||
$this->assertRaw('<h3>' . t('Modules') . '</h3>');
|
||||
$this->assertNoText(t('Update available'));
|
||||
$this->assertText(t('No available releases found'));
|
||||
$this->assertNoRaw(\Drupal::l(t('AAA Update test'), Url::fromUri('http://example.com/project/aaa_update_test')));
|
||||
$this->assertNoRaw(Link::fromTextAndUrl(t('AAA Update test'), Url::fromUri('http://example.com/project/aaa_update_test'))->toString());
|
||||
|
||||
$available = update_get_available();
|
||||
$this->assertFalse(isset($available['aaa_update_test']['fetch_status']), 'Results are cached even if no releases are available.');
|
||||
|
|
@ -61,7 +62,7 @@ class UpdateContribTest extends UpdateTestBase {
|
|||
* Tests the basic functionality of a contrib module on the status report.
|
||||
*/
|
||||
public function testUpdateContribBasic() {
|
||||
$project_link = \Drupal::l(t('AAA Update test'), Url::fromUri('http://example.com/project/aaa_update_test'));
|
||||
$project_link = Link::fromTextAndUrl(t('AAA Update test'), Url::fromUri('http://example.com/project/aaa_update_test'))->toString();
|
||||
$system_info = [
|
||||
'#all' => [
|
||||
'version' => '8.0.0',
|
||||
|
|
@ -167,10 +168,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(\Drupal::l(t('AAA Update test'), Url::fromUri('http://example.com/project/aaa_update_test')), 'Link to aaa_update_test project does not appear.');
|
||||
$this->assertNoRaw(Link::fromTextAndUrl(t('AAA Update test'), Url::fromUri('http://example.com/project/aaa_update_test'))->toString(), 'Link to aaa_update_test project does not appear.');
|
||||
// The other two should be listed as projects.
|
||||
$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.');
|
||||
$this->assertRaw(Link::fromTextAndUrl(t('BBB Update test'), Url::fromUri('http://example.com/project/bbb_update_test'))->toString(), 'Link to bbb_update_test project appears.');
|
||||
$this->assertRaw(Link::fromTextAndUrl(t('CCC Update test'), Url::fromUri('http://example.com/project/ccc_update_test'))->toString(), '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
|
||||
|
|
@ -217,7 +218,7 @@ class UpdateContribTest extends UpdateTestBase {
|
|||
];
|
||||
$this->refreshUpdateStatus($xml_mapping);
|
||||
$this->assertText(t('Security update required!'));
|
||||
$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.');
|
||||
$this->assertRaw(Link::fromTextAndUrl(t('Update test base theme'), Url::fromUri('http://example.com/project/update_test_basetheme'))->toString(), 'Link to the Update test base theme project appears.');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -267,8 +268,8 @@ class UpdateContribTest extends UpdateTestBase {
|
|||
'update_test_subtheme' => '1_0',
|
||||
'update_test_basetheme' => '1_1-sec',
|
||||
];
|
||||
$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'));
|
||||
$base_theme_project_link = Link::fromTextAndUrl(t('Update test base theme'), Url::fromUri('http://example.com/project/update_test_basetheme'))->toString();
|
||||
$sub_theme_project_link = Link::fromTextAndUrl(t('Update test subtheme'), Url::fromUri('http://example.com/project/update_test_subtheme'))->toString();
|
||||
foreach ([TRUE, FALSE] as $check_disabled) {
|
||||
$update_settings->set('check.disabled_extensions', $check_disabled)->save();
|
||||
$this->refreshUpdateStatus($xml_mapping);
|
||||
|
|
@ -373,9 +374,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(\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.');
|
||||
$this->assertRaw(Link::fromTextAndUrl(t('AAA Update test'), Url::fromUri('http://example.com/project/aaa_update_test'))->toString(), 'Link to aaa_update_test project appears.');
|
||||
$this->assertNoRaw(Link::fromTextAndUrl(t('BBB Update test'), Url::fromUri('http://example.com/project/bbb_update_test'))->toString(), 'Link to bbb_update_test project does not appear.');
|
||||
$this->assertRaw(Link::fromTextAndUrl(t('CCC Update test'), Url::fromUri('http://example.com/project/ccc_update_test'))->toString(), 'Link to bbb_update_test project appears.');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -417,7 +418,7 @@ class UpdateContribTest extends UpdateTestBase {
|
|||
$this->drupalGet('admin/reports/updates');
|
||||
$this->assertRaw('<h3>' . t('Modules') . '</h3>');
|
||||
$this->assertText(t('Security update required!'));
|
||||
$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->assertRaw(Link::fromTextAndUrl(t('AAA Update test'), Url::fromUri('http://example.com/project/aaa_update_test'))->toString(), 'Link to aaa_update_test project appears.');
|
||||
|
||||
// Visit the reports page again without the altering and make sure the
|
||||
// status is back to normal.
|
||||
|
|
@ -425,7 +426,7 @@ class UpdateContribTest extends UpdateTestBase {
|
|||
$this->drupalGet('admin/reports/updates');
|
||||
$this->assertRaw('<h3>' . t('Modules') . '</h3>');
|
||||
$this->assertNoText(t('Security update required!'));
|
||||
$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->assertRaw(Link::fromTextAndUrl(t('AAA Update test'), Url::fromUri('http://example.com/project/aaa_update_test'))->toString(), '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();
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Drupal\Tests\update\Functional;
|
||||
|
||||
use Drupal\Core\Link;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\Tests\Traits\Core\CronRunTrait;
|
||||
|
||||
|
|
@ -81,9 +82,9 @@ class UpdateCoreTest extends UpdateTestBase {
|
|||
$this->clickLink(t('Check manually'));
|
||||
$this->checkForMetaRefresh();
|
||||
$this->assertNoText(t('Security update required!'));
|
||||
$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.');
|
||||
$this->assertRaw(Link::fromTextAndUrl("8.$minor_version.1" . $extra_version, Url::fromUri("http://example.com/drupal-8-$minor_version-1$extra_version-release"))->toString(), 'Link to release appears.');
|
||||
$this->assertRaw(Link::fromTextAndUrl(t('Download'), Url::fromUri("http://example.com/drupal-8-$minor_version-1$extra_version.tar.gz"))->toString(), 'Link to download appears.');
|
||||
$this->assertRaw(Link::fromTextAndUrl(t('Release notes'), Url::fromUri("http://example.com/drupal-8-$minor_version-1$extra_version-release"))->toString(), 'Link to release notes appears.');
|
||||
|
||||
switch ($minor_version) {
|
||||
case 0:
|
||||
|
|
@ -145,9 +146,9 @@ class UpdateCoreTest extends UpdateTestBase {
|
|||
$this->clickLink(t('Check manually'));
|
||||
$this->checkForMetaRefresh();
|
||||
$this->assertNoText(t('Security update required!'));
|
||||
$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->assertRaw(Link::fromTextAndUrl('9.0.0', Url::fromUri("http://example.com/drupal-9-0-0-release"))->toString(), 'Link to release appears.');
|
||||
$this->assertRaw(Link::fromTextAndUrl(t('Download'), Url::fromUri("http://example.com/drupal-9-0-0.tar.gz"))->toString(), 'Link to download appears.');
|
||||
$this->assertRaw(Link::fromTextAndUrl(t('Release notes'), Url::fromUri("http://example.com/drupal-9-0-0-release"))->toString(), 'Link to release notes appears.');
|
||||
$this->assertNoText(t('Up to date'));
|
||||
$this->assertText(t('Not supported!'));
|
||||
$this->assertText(t('Recommended version:'));
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
namespace Drupal\Tests\update\Functional;
|
||||
|
||||
use Drupal\Core\DrupalKernel;
|
||||
use Drupal\Core\Link;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
|
|
@ -92,7 +93,7 @@ abstract class UpdateTestBase extends BrowserTestBase {
|
|||
*/
|
||||
protected function standardTests() {
|
||||
$this->assertRaw('<h3>' . t('Drupal core') . '</h3>');
|
||||
$this->assertRaw(\Drupal::l(t('Drupal'), Url::fromUri('http://example.com/project/drupal')), 'Link to the Drupal project appears.');
|
||||
$this->assertRaw(Link::fromTextAndUrl(t('Drupal'), Url::fromUri('http://example.com/project/drupal'))->toString(), 'Link to the Drupal project appears.');
|
||||
$this->assertNoText(t('No available releases found'));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
* Install, update, and uninstall functions for the Update Manager module.
|
||||
*/
|
||||
|
||||
use Drupal\Core\Link;
|
||||
use Drupal\Core\Url;
|
||||
|
||||
/**
|
||||
|
|
@ -148,7 +149,7 @@ function _update_requirement_check($project, $type) {
|
|||
if ($status != UPDATE_CURRENT && $type == 'core' && isset($project['recommended'])) {
|
||||
$requirement_label .= ' ' . t('(version @version available)', ['@version' => $project['recommended']]);
|
||||
}
|
||||
$requirement['value'] = \Drupal::l($requirement_label, new Url(_update_manager_access() ? 'update.report_update' : 'update.status'));
|
||||
$requirement['value'] = Link::fromTextAndUrl($requirement_label, Url::fromRoute(_update_manager_access() ? 'update.report_update' : 'update.status'))->toString();
|
||||
return $requirement;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@
|
|||
*/
|
||||
|
||||
use Drupal\Core\File\Exception\FileException;
|
||||
use Drupal\Core\Link;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Routing\RouteMatchInterface;
|
||||
|
|
@ -652,7 +653,7 @@ function _update_project_status_sort($a, $b) {
|
|||
*/
|
||||
function template_preprocess_update_last_check(&$variables) {
|
||||
$variables['time'] = \Drupal::service('date.formatter')->formatTimeDiffSince($variables['last']);
|
||||
$variables['link'] = \Drupal::l(t('Check manually'), new Url('update.manual_status', [], ['query' => \Drupal::destination()->getAsArray()]));
|
||||
$variables['link'] = Link::fromTextAndUrl(t('Check manually'), Url::fromRoute('update.manual_status', [], ['query' => \Drupal::destination()->getAsArray()]))->toString();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ use Drupal\Core\Form\FormStateInterface;
|
|||
use Drupal\Core\Language\LanguageInterface;
|
||||
use Drupal\Core\Plugin\PluginDependencyTrait;
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
use Drupal\Core\Link;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\views\Form\ViewsForm;
|
||||
use Drupal\views\Plugin\views\area\AreaPluginBase;
|
||||
|
|
@ -1028,7 +1029,7 @@ abstract class DisplayPluginBase extends PluginBase implements DisplayPluginInte
|
|||
$title = $text;
|
||||
}
|
||||
|
||||
return \Drupal::l($text, new Url('views_ui.form_display', [
|
||||
return Link::fromTextAndUrl($text, Url::fromRoute('views_ui.form_display', [
|
||||
'js' => 'nojs',
|
||||
'view' => $this->view->storage->id(),
|
||||
'display_id' => $this->display['id'],
|
||||
|
|
@ -1039,7 +1040,7 @@ abstract class DisplayPluginBase extends PluginBase implements DisplayPluginInte
|
|||
'title' => $title,
|
||||
'id' => Html::getUniqueId('views-' . $this->display['id'] . '-' . $section),
|
||||
],
|
||||
]));
|
||||
]))->toString();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
namespace Drupal\views\Plugin\views\field;
|
||||
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Link;
|
||||
use Drupal\Core\Url as CoreUrl;
|
||||
use Drupal\views\ResultRow;
|
||||
|
||||
|
|
@ -46,7 +47,7 @@ class Url extends FieldPluginBase {
|
|||
if (!empty($this->options['display_as_link'])) {
|
||||
// @todo Views should expect and store a leading /. See:
|
||||
// https://www.drupal.org/node/2423913
|
||||
return \Drupal::l($this->sanitizeValue($value), CoreUrl::fromUserInput('/' . $value));
|
||||
return Link::fromTextAndUrl($this->sanitizeValue($value), CoreUrl::fromUserInput('/' . $value))->toString();
|
||||
}
|
||||
else {
|
||||
return $this->sanitizeValue($value, 'url');
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ use Drupal\comment\CommentInterface;
|
|||
use Drupal\comment\Tests\CommentTestTrait;
|
||||
use Drupal\Core\Field\FieldStorageDefinitionInterface;
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
use Drupal\Core\Link;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\views\Views;
|
||||
use Drupal\comment\Entity\Comment;
|
||||
|
|
@ -88,7 +89,7 @@ class DefaultViewsTest extends ViewTestBase {
|
|||
if ($i % 2) {
|
||||
$values['promote'] = TRUE;
|
||||
}
|
||||
$values['body'][]['value'] = \Drupal::l('Node ' . 1, new Url('entity.node.canonical', ['node' => 1]));
|
||||
$values['body'][]['value'] = Link::fromTextAndUrl('Node ' . 1, Url::fromRoute('entity.node.canonical', ['node' => 1]))->toString();
|
||||
|
||||
$node = $this->drupalCreateNode($values);
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Drupal\Tests\views\Kernel\Handler;
|
||||
|
||||
use Drupal\Core\Link;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
|
||||
use Drupal\views\Views;
|
||||
|
|
@ -61,7 +62,7 @@ class FieldUrlTest extends ViewsKernelTestBase {
|
|||
|
||||
$this->executeView($view);
|
||||
|
||||
$this->assertEqual(\Drupal::l('John', Url::fromUri('base:John'))->getGeneratedLink(), $view->field['name']->advancedRender($view->result[0]));
|
||||
$this->assertEqual(Link::fromTextAndUrl('John', Url::fromUri('base:John'))->toString(), $view->field['name']->advancedRender($view->result[0]));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ namespace Drupal\views_ui\Form\Ajax;
|
|||
|
||||
use Drupal\Component\Render\FormattableMarkup;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Link;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\views\ViewEntityInterface;
|
||||
use Drupal\views\ViewExecutable;
|
||||
|
|
@ -126,7 +127,7 @@ class Rearrange extends ViewsFormBase {
|
|||
'#id' => 'views-removed-' . $id,
|
||||
'#attributes' => ['class' => ['views-remove-checkbox']],
|
||||
'#default_value' => 0,
|
||||
'#suffix' => \Drupal::l(new FormattableMarkup('<span>@text</span>', ['@text' => $this->t('Remove')]),
|
||||
'#suffix' => Link::fromTextAndUrl(new FormattableMarkup('<span>@text</span>', ['@text' => $this->t('Remove')]),
|
||||
Url::fromRoute('<none>', [], [
|
||||
'attributes' => [
|
||||
'id' => 'views-remove-link-' . $id,
|
||||
|
|
@ -135,7 +136,7 @@ class Rearrange extends ViewsFormBase {
|
|||
'title' => $this->t('Remove this item'),
|
||||
],
|
||||
])
|
||||
),
|
||||
)->toString(),
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,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\Link;
|
||||
use Drupal\Core\Url;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\HttpKernel\Exception\NotAcceptableHttpException;
|
||||
|
|
@ -268,7 +269,7 @@ class ViewListBuilder extends ConfigEntityListBuilder {
|
|||
try {
|
||||
// @todo Views should expect and store a leading /. See:
|
||||
// https://www.drupal.org/node/2423913
|
||||
$rendered_path = \Drupal::l('/' . $path, Url::fromUserInput('/' . $path));
|
||||
$rendered_path = Link::fromTextAndUrl('/' . $path, Url::fromUserInput('/' . $path))->toString();
|
||||
}
|
||||
catch (NotAcceptableHttpException $e) {
|
||||
$rendered_path = '/' . $path;
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ use Drupal\Component\Utility\Html;
|
|||
use Drupal\Component\Utility\Timer;
|
||||
use Drupal\Core\EventSubscriber\AjaxResponseSubscriber;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Link;
|
||||
use Drupal\Core\TempStore\Lock;
|
||||
use Drupal\views\Views;
|
||||
use Drupal\Core\Entity\EntityStorageInterface;
|
||||
|
|
@ -699,7 +700,7 @@ class ViewUI implements ViewEntityInterface {
|
|||
if (isset($path)) {
|
||||
// @todo Views should expect and store a leading /. See:
|
||||
// https://www.drupal.org/node/2423913
|
||||
$path = \Drupal::l($path->toString(), $path);
|
||||
$path = Link::fromTextAndUrl($path->toString(), $path)->toString();
|
||||
}
|
||||
else {
|
||||
$path = t('This display has no path.');
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ class LinkGenerationTest extends KernelTestBase {
|
|||
$renderer = \Drupal::service('renderer');
|
||||
|
||||
$link = $renderer->executeInRenderContext(new RenderContext(), function () use ($url) {
|
||||
return \Drupal::l(['#markup' => '<em>link with markup</em>'], $url);
|
||||
return \Drupal::service('link_generator')->generate(['#markup' => '<em>link with markup</em>'], $url);
|
||||
});
|
||||
$this->setRawContent($link);
|
||||
$this->assertTrue($link instanceof MarkupInterface, 'The output of link generation is marked safe as it is a link.');
|
||||
|
|
@ -34,7 +34,7 @@ class LinkGenerationTest extends KernelTestBase {
|
|||
// Test just adding text to an already safe string.
|
||||
\Drupal::state()->set('link_generation_test_link_alter', TRUE);
|
||||
$link = $renderer->executeInRenderContext(new RenderContext(), function () use ($url) {
|
||||
return \Drupal::l(['#markup' => '<em>link with markup</em>'], $url);
|
||||
return \Drupal::service('link_generator')->generate(['#markup' => '<em>link with markup</em>'], $url);
|
||||
});
|
||||
$this->setRawContent($link);
|
||||
$this->assertTrue($link instanceof MarkupInterface, 'The output of link generation is marked safe as it is a link.');
|
||||
|
|
@ -44,7 +44,7 @@ class LinkGenerationTest extends KernelTestBase {
|
|||
// Test passing a safe string to t().
|
||||
\Drupal::state()->set('link_generation_test_link_alter_safe', TRUE);
|
||||
$link = $renderer->executeInRenderContext(new RenderContext(), function () use ($url) {
|
||||
return \Drupal::l(['#markup' => '<em>link with markup</em>'], $url);
|
||||
return \Drupal::service('link_generator')->generate(['#markup' => '<em>link with markup</em>'], $url);
|
||||
});
|
||||
$this->setRawContent($link);
|
||||
$this->assertTrue($link instanceof MarkupInterface, 'The output of link generation is marked safe as it is a link.');
|
||||
|
|
@ -53,7 +53,7 @@ class LinkGenerationTest extends KernelTestBase {
|
|||
|
||||
// Test passing an unsafe string to t().
|
||||
$link = $renderer->executeInRenderContext(new RenderContext(), function () use ($url) {
|
||||
return \Drupal::l('<em>link with markup</em>', $url);
|
||||
return \Drupal::service('link_generator')->generate('<em>link with markup</em>', $url);
|
||||
});
|
||||
$this->setRawContent($link);
|
||||
$this->assertTrue($link instanceof MarkupInterface, 'The output of link generation is marked safe as it is a link.');
|
||||
|
|
|
|||
|
|
@ -392,6 +392,11 @@ class DrupalTest extends UnitTestCase {
|
|||
* Tests the l() method.
|
||||
*
|
||||
* @covers ::l
|
||||
*
|
||||
* @group legacy
|
||||
*
|
||||
* @expectedDeprecation \Drupal::l() is deprecated in drupal:8.0.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Link::fromTextAndUrl() instead. See https://www.drupal.org/node/2614344
|
||||
*
|
||||
* @see \Drupal\Core\Utility\LinkGeneratorInterface::generate()
|
||||
*/
|
||||
public function testL() {
|
||||
|
|
|
|||
Loading…
Reference in New Issue