Commit 4f49087b authored by alexpott's avatar alexpott

Issue #2277103 by tim.plunkett, pwolanin, Wim Leers, dawehner, hotpizzas:...

Issue #2277103 by tim.plunkett, pwolanin, Wim Leers, dawehner, hotpizzas: Switch Drupal::l() and LinkGenerator to expect a Url object.
parent f085b7b6
......@@ -21,6 +21,7 @@
*/
use Drupal\Core\DrupalKernel;
use Drupal\Core\Url;
use Symfony\Component\HttpFoundation\Request;
use Drupal\Core\Site\Settings;
use Drupal\Core\Page\DefaultHtmlPageRenderer;
......@@ -109,8 +110,8 @@ function authorize_access_allowed() {
}
else {
$links = array_merge($links, array(
\Drupal::l(t('Administration pages'), 'system.admin'),
\Drupal::l(t('Front page'), '<front>'),
\Drupal::l(t('Administration pages'), new Url('system.admin')),
\Drupal::l(t('Front page'), new Url('<front>')),
));
}
......
......@@ -6,6 +6,7 @@
*/
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Url;
/**
* Static Service Container wrapper.
......@@ -531,13 +532,9 @@ public static function linkGenerator() {
*
* @param string|array $text
* The link text for the anchor tag as a translated string or render array.
* @param string $route_name
* The name of the route to use to generate the link.
* @param array $parameters
* (optional) Any parameters needed to render the route path pattern.
* @param array $options
* (optional) An associative array of additional options. Defaults to an
* empty array. It may contain the following elements:
* @param \Drupal\Core\Url $url
* The URL object used for the link. Amongst its options, the following may
* be set to affect the generated link:
* - 'query': An array of query key/value-pairs (without any URL-encoding) to
* append to the URL.
* - absolute: Whether to force the output to be an absolute link (beginning
......@@ -572,8 +569,8 @@ public static function linkGenerator() {
* @see \Drupal\Core\Routing\UrlGeneratorInterface::generateFromRoute()
* @see \Drupal\Core\Utility\LinkGeneratorInterface::generate()
*/
public static function l($text, $route_name, array $parameters = array(), array $options = array()) {
return static::$container->get('link_generator')->generate($text, $route_name, $parameters, $options);
public static function l($text, Url $url) {
return static::$container->get('link_generator')->generate($text, $url);
}
/**
......
......@@ -50,9 +50,7 @@ public function getGroup();
* Returns the link options passed to the link generator.
*
* @return array
* The options as expected by LinkGeneratorInterface::generate()
*
* @see \Drupal\Core\Utility\LinkGeneratorInterface::generate()
* An associative array of options.
*/
public function getOptions();
......
......@@ -30,8 +30,6 @@ public function getRouteName();
*
* @return array
* An array of parameter names and values.
*
* @see \Drupal\Core\Utility\LinkGeneratorInterface::generate()
*/
public function getRouteParameters(Request $request);
......@@ -50,8 +48,6 @@ public function getWeight();
*
* @return array
* An associative array of options.
*
* @see \Drupal\Core\Utility\LinkGeneratorInterface::generate()
*/
public function getOptions(Request $request);
......
......@@ -41,8 +41,6 @@ public function getTitle();
*
* @return array
* An array of parameter names and values.
*
* @see \Drupal\Core\Utility\LinkGeneratorInterface::generate()
*/
public function getRouteParameters(Request $request);
......@@ -61,9 +59,7 @@ public function getWeight();
* The HttpRequest object representing the current request.
*
* @return array
* An array of options.
*
* @see \Drupal\Core\Utility\LinkGeneratorInterface::generate()
* An associative array of options.
*/
public function getOptions(Request $request);
......
......@@ -110,6 +110,7 @@ public function isDeletable();
* Returns the route name, if available.
*
* @return string
* The name of the route this menu link links to.
*/
public function getRouteName();
......@@ -117,6 +118,7 @@ public function getRouteName();
* Returns the route parameters, if available.
*
* @return array
* An array of parameter names and values.
*/
public function getRouteParameters();
......@@ -136,7 +138,7 @@ public function getUrlObject($title_attribute = TRUE);
* Returns the options for this link.
*
* @return array
* The options for the menu link.
* An associative array of options.
*/
public function getOptions();
......
......@@ -7,6 +7,8 @@
namespace Drupal\Core\Render\Element;
use Drupal\Core\Url;
/**
* Provides a link render element.
*
......@@ -83,7 +85,7 @@ public static function preRenderLink($element) {
if (isset($element['#route_name'])) {
$element['#route_parameters'] = empty($element['#route_parameters']) ? array() : $element['#route_parameters'];
$element['#markup'] = \Drupal::linkGenerator()->generate($element['#title'], $element['#route_name'], $element['#route_parameters'], $element['#options']);
$element['#markup'] = \Drupal::l($element['#title'], new Url($element['#route_name'], $element['#route_parameters'], $element['#options']));
}
else {
$element['#markup'] = l($element['#title'], $element['#href'], $element['#options']);
......
......@@ -7,6 +7,7 @@
namespace Drupal\Core\Routing;
use Drupal\Core\Url;
use Drupal\Core\Utility\LinkGeneratorInterface;
use Drupal\Core\Routing\UrlGeneratorInterface;
......@@ -36,8 +37,8 @@ trait LinkGeneratorTrait {
* @return string
* An HTML string containing a link to the given route and parameters.
*/
protected function l($text, $route_name, array $parameters = array(), array $options = array()) {
return $this->getLinkGenerator()->generate($text, $route_name, $parameters, $options);
protected function l($text, Url $url) {
return $this->getLinkGenerator()->generate($text, $url);
}
/**
......
......@@ -210,7 +210,7 @@ public function getUrlFromPath($path, $options = array()) {
*/
public function getLink($text, $url) {
if ($url instanceof Url) {
return $this->linkGenerator->generateFromUrl($text, $url);
return $this->linkGenerator->generate($text, $url);
}
else {
// @todo Convert once https://www.drupal.org/node/2306901 is in
......
......@@ -7,6 +7,8 @@
namespace Drupal\Core\Updater;
use Drupal\Core\Url;
/**
* Defines a class for updating modules using
* Drupal\Core\FileTransfer\FileTransfer classes via authorize.php.
......@@ -98,9 +100,9 @@ public function getSchemaUpdates() {
*/
public function postInstallTasks() {
return array(
\Drupal::l(t('Install another module'), 'update.module_install'),
\Drupal::l(t('Enable newly added modules'), 'system.modules_list'),
\Drupal::l(t('Administration pages'), 'system.admin'),
\Drupal::l(t('Install another module'), new Url('update.module_install')),
\Drupal::l(t('Enable newly added modules'), new Url('system.modules_list')),
\Drupal::l(t('Administration pages'), new Url('system.admin')),
);
}
......
......@@ -7,6 +7,8 @@
namespace Drupal\Core\Updater;
use Drupal\Core\Url;
/**
* Defines a class for updating themes using
* Drupal\Core\FileTransfer\FileTransfer classes via authorize.php.
......@@ -82,8 +84,8 @@ public function postInstall() {
*/
public function postInstallTasks() {
return array(
\Drupal::l(t('Install newly added themes'), 'system.themes_page'),
\Drupal::l(t('Administration pages'), 'system.admin'),
\Drupal::l(t('Install newly added themes'), new Url('system.themes_page')),
\Drupal::l(t('Administration pages'), new Url('system.admin')),
);
}
}
......@@ -53,7 +53,7 @@ public function __construct(UrlGeneratorInterface $url_generator, ModuleHandlerI
* {@inheritdoc}
*/
public function generateFromLink(Link $link) {
return $this->generateFromUrl($link->getText(), $link->getUrl());
return $this->generate($link->getText(), $link->getUrl());
}
/**
......@@ -68,7 +68,11 @@ public function generateFromLink(Link $link) {
*
* @see system_page_build()
*/
public function generateFromUrl($text, Url $url) {
public function generate($text, Url $url) {
// Performance: avoid Url::toString() needing to retrieve the URL generator
// service from the container.
$url->setUrlGenerator($this->urlGenerator);
// Start building a structured representation of our link to be altered later.
$variables = array(
// @todo Inject the service when drupal_render() is converted to one.
......@@ -136,13 +140,4 @@ public function generateFromUrl($text, Url $url) {
return SafeMarkup::set('<a href="' . $url . '"' . $attributes . '>' . $text . '</a>');
}
/**
* {@inheritdoc}
*/
public function generate($text, $route_name, array $parameters = array(), array $options = array()) {
$url = new Url($route_name, $parameters, $options);
$url->setUrlGenerator($this->urlGenerator);
return $this->generateFromUrl($text, $url);
}
}
......@@ -16,11 +16,7 @@
interface LinkGeneratorInterface {
/**
* Renders a link to a route given a route name and its parameters.
*
* This function correctly handles aliased paths and sanitizing text, so all
* internal links output by modules should be generated by this function if
* possible.
* Renders a link to a URL.
*
* However, for links enclosed in translatable text you should use t() and
* embed the HTML anchor tag directly in the translated string. For example:
......@@ -32,18 +28,9 @@ interface LinkGeneratorInterface {
*
* @param string|array $text
* The link text for the anchor tag as a translated string or render array.
* @param string $route_name
* The name of the route to use to generate the link.
* @param array $parameters
* (optional) Any parameters needed to render the route path pattern.
* @param array $options
* (optional) An associative array of additional options. Defaults to an
* empty array. It may contain the following elements:
* - 'query': An array of query key/value-pairs (without any URL-encoding)
* to append to the URL.
* - absolute: Whether to force the output to be an absolute link (beginning
* with http:). Useful for links that will be displayed outside the site,
* such as in an RSS feed. Defaults to FALSE.
* @param \Drupal\Core\Url $url
* The URL object used for the link. Amongst its options, the following may
* be set to affect the generated link:
* - attributes: An associative array of HTML attributes to apply to the
* anchor tag. If element 'class' is included, it must be an array; 'title'
* must be a string; other elements are more flexible, as they just need
......@@ -75,23 +62,8 @@ interface LinkGeneratorInterface {
* @throws \Symfony\Component\Routing\Exception\InvalidParameterException
* Thrown when a parameter value for a placeholder is not correct because it
* does not match the requirement.
*
* @see \Drupal\Core\Routing\UrlGenerator::generateFromRoute()
*/
public function generate($text, $route_name, array $parameters = array(), array $options = array());
/**
* Renders a link to a URL.
*
* @param string $text
* The link text for the anchor tag as a translated string.
* @param \Drupal\Core\Url $url
* The URL object used for the link.
*
* @return string
* An HTML string containing a link to the given route and parameters.
*/
public function generateFromUrl($text, Url $url);
public function generate($text, Url $url);
/**
* Renders a link from a link object.
......
......@@ -119,9 +119,10 @@ public function adminOverview() {
$header = array($this->t('Title'), $this->t('Items'), $this->t('Last update'), $this->t('Next update'), $this->t('Operations'));
$rows = array();
/** @var \Drupal\aggregator\FeedInterface[] $feeds */
foreach ($feeds as $feed) {
$row = array();
$row[] = $this->getLinkGenerator()->generateFromUrl($feed->label(), $feed->urlInfo());
$row[] = $feed->link();
$row[] = $this->dateFormatter->formatInterval($entity_manager->getStorage('aggregator_item')->getItemCount($feed), '1 item', '@count items');
$last_checked = $feed->getLastCheckedTime();
$refresh_rate = $feed->getRefreshRate();
......
......@@ -12,6 +12,7 @@
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
......@@ -70,7 +71,7 @@ public function save(array $form, FormStateInterface $form_state) {
$form_state->setRedirectUrl($feed->urlInfo('canonical'));
}
else {
$this->logger('aggregator')->notice('Feed %feed added.', array('%feed' => $feed->label(), 'link' => \Drupal::l($this->t('View'), 'aggregator.admin_overview')));
$this->logger('aggregator')->notice('Feed %feed added.', array('%feed' => $feed->label(), 'link' => $this->l($this->t('View'), new Url('aggregator.admin_overview'))));
drupal_set_message($this->t('The feed %feed has been added.', array('%feed' => $feed->label())));
}
}
......
......@@ -7,6 +7,7 @@
use Drupal\block\BlockInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Url;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\system\Entity\Menu;
use Drupal\block\Entity\Block;
......@@ -41,7 +42,7 @@ function block_help($route_name, RouteMatchInterface $route_match) {
$demo_theme = $route_match->getParameter('theme') ?: \Drupal::config('system.theme')->get('default');
$themes = list_themes();
$output = '<p>' . t('This page provides a drag-and-drop interface for adding a block to a region, and for controlling the order of blocks within regions. To add a block to a region, or to configure its specific title and visibility settings, click the block title under <em>Place blocks</em>. Since not all themes implement the same regions, or display regions in the same way, blocks are positioned on a per-theme basis. Remember that your changes will not be saved until you click the <em>Save blocks</em> button at the bottom of the page.') . '</p>';
$output .= '<p>' . \Drupal::l(t('Demonstrate block regions (!theme)', array('!theme' => $themes[$demo_theme]->info['name'])), 'block.admin_demo', array('theme' => $demo_theme)) . '</p>';
$output .= '<p>' . \Drupal::l(t('Demonstrate block regions (!theme)', array('!theme' => $themes[$demo_theme]->info['name'])), new Url('block.admin_demo', array('theme' => $demo_theme))) . '</p>';
return $output;
}
}
......
......@@ -6,6 +6,7 @@
*/
use Drupal\Component\Utility\Xss;
use Drupal\Core\Url;
use Drupal\block_content\Entity\BlockContentType;
use Drupal\block_content\Entity\BlockContent;
use Symfony\Component\HttpFoundation\RedirectResponse;
......@@ -26,7 +27,7 @@ function template_preprocess_block_content_add_list(&$variables) {
$query = \Drupal::request()->query->all();
foreach ($variables['content'] as $type) {
$variables['types'][$type->id()] = array(
'link' => \Drupal::l($type->label(), 'block_content.add_form', array('block_content_type' => $type->id()), array('query' => $query)),
'link' => \Drupal::l($type->label(), new Url('block_content.add_form', array('block_content_type' => $type->id()), array('query' => $query))),
'description' => Xss::filterAdmin($type->description),
'title' => $type->label(),
'localized_options' => array(
......
......@@ -521,7 +521,7 @@ function theme_book_link(array $variables) {
/** @var \Drupal\Core\Url $url */
$url = $element['#url'];
$url->setOptions($element['#localized_options'] + $url->getOptions());
$output = \Drupal::linkGenerator()->generateFromUrl($element['#title'], $url);
$output = \Drupal::l($element['#title'], $url);
return '<li' . new Attribute($element['#attributes']) . '>' . $output . $sub_menu . "</li>\n";
}
......
......@@ -77,7 +77,7 @@ public function adminOverview() {
$url->setOptions($book['options']);
}
$row = array(
$this->getLinkGenerator()->generateFromUrl($book['title'], $url),
$this->l($book['title'], $url),
);
$links = array();
$links['edit'] = array(
......@@ -110,7 +110,7 @@ public function adminOverview() {
public function bookRender() {
$book_list = array();
foreach ($this->bookManager->getAllBooks() as $book) {
$book_list[] = $this->getLinkGenerator()->generateFromUrl($book['title'], $book['url']);
$book_list[] = $this->l($book['title'], $book['url']);
}
return array(
'#theme' => 'item_list',
......
......@@ -121,7 +121,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
$node->book['link_title'] = $values['title'];
$node->setNewRevision();
$node->save();
$this->logger('content')->notice('book: updated %title.', array('%title' => $node->label(), 'link' => $this->getLinkGenerator()->generateFromUrl($this->t('View'), $node->urlInfo())));
$this->logger('content')->notice('book: updated %title.', array('%title' => $node->label(), 'link' => $node->link($this->t('View'))));
}
}
}
......
......@@ -190,21 +190,21 @@ function checkBookNode(EntityInterface $node, $nodes, $previous = FALSE, $up = F
/** @var \Drupal\Core\Url $url */
$url = $previous->urlInfo();
$url->setOptions(array('html' => TRUE, 'attributes' => array('rel' => array('prev'), 'title' => t('Go to previous page'))));
$this->assertRaw(\Drupal::linkGenerator()->generateFromUrl('<b>‹</b> ' . $previous->label(), $url), 'Previous page link found.');
$this->assertRaw(\Drupal::l('<b>‹</b> ' . $previous->label(), $url), 'Previous page link found.');
}
if ($up) {
/** @var \Drupal\Core\Url $url */
$url = $up->urlInfo();
$url->setOptions(array('html'=> TRUE, 'attributes' => array('title' => t('Go to parent page'))));
$this->assertRaw(\Drupal::linkGenerator()->generateFromUrl('Up', $url), 'Up page link found.');
$this->assertRaw(\Drupal::l('Up', $url), 'Up page link found.');
}
if ($next) {
/** @var \Drupal\Core\Url $url */
$url = $next->urlInfo();
$url->setOptions(array('html'=> TRUE, 'attributes' => array('rel' => array('next'), 'title' => t('Go to next page'))));
$this->assertRaw(\Drupal::linkGenerator()->generateFromUrl($next->label() . ' <b>›</b>', $url), 'Next page link found.');
$this->assertRaw(\Drupal::l($next->label() . ' <b>›</b>', $url), 'Next page link found.');
}
// Compute the expected breadcrumb.
......
......@@ -727,17 +727,17 @@ function template_preprocess_comment(&$variables) {
$variables['signature'] = '';
}
if (isset($comment->in_preview)) {
$variables['title'] = \Drupal::l($comment->getSubject(), '<front>');
$variables['permalink'] = \Drupal::l(t('Permalink'), '<front>');
$variables['title'] = \Drupal::l($comment->getSubject(), new Url('<front>'));
$variables['permalink'] = \Drupal::l(t('Permalink'), new Url('<front>'));
}
else {
$uri = $comment->urlInfo();
$attributes = $uri->getOption('attributes') ?: array();
$attributes += array('class' => array('permalink'), 'rel' => 'bookmark');
$uri->setOption('attributes', $attributes);
$variables['title'] = \Drupal::linkGenerator()->generateFromUrl($comment->getSubject(), $uri);
$variables['title'] = \Drupal::l($comment->getSubject(), $uri);
$variables['permalink'] = \Drupal::linkGenerator()->generateFromUrl(t('Permalink'), $comment->permalink());
$variables['permalink'] = \Drupal::l(t('Permalink'), $comment->permalink());
}
$variables['submitted'] = t('Submitted by !username on !datetime', array('!username' => $variables['author'], '!datetime' => $variables['created']));
......@@ -764,8 +764,8 @@ function template_preprocess_comment(&$variables) {
$attributes = $permalink_uri_parent->getOption('attributes') ?: array();
$attributes += array('class' => array('permalink'), 'rel' => 'bookmark');
$permalink_uri_parent->setOption('attributes', $attributes);
$variables['parent_title'] = \Drupal::linkGenerator()->generateFromUrl($comment_parent->getSubject(), $permalink_uri_parent);
$variables['parent_permalink'] = \Drupal::linkGenerator()->generateFromUrl(t('Parent permalink'), $permalink_uri_parent);
$variables['parent_title'] = \Drupal::l($comment_parent->getSubject(), $permalink_uri_parent);
$variables['parent_permalink'] = \Drupal::l(t('Parent permalink'), $permalink_uri_parent);
$variables['parent'] = t('In reply to !parent_title by !parent_username',
array('!parent_username' => $variables['parent_author'], '!parent_title' => $variables['parent_title']));
}
......
......@@ -372,7 +372,7 @@ public function save(array $form, FormStateInterface $form_state) {
// Add a log entry.
$logger->notice('Comment posted: %subject.', array(
'%subject' => $comment->getSubject(),
'link' => $this->getLinkGenerator()->generateFromUrl(t('View'), $comment->urlInfo()->setOption('fragment', 'comment-' . $comment->id()))
'link' => $this->l(t('View'), $comment->urlInfo()->setOption('fragment', 'comment-' . $comment->id()))
));
// Explain the approval queue if necessary.
......
......@@ -125,7 +125,7 @@ public function overview(Request $request, $entity_type_id = NULL) {
$link = isset($links->links[$langcode]['url']) ? $links->links[$langcode] : array('url' => $entity->urlInfo());
if (!empty($link['url'])) {
$link['url']->setOption('language', $language);
$row_title = $this->getLinkGenerator()->generateFromUrl($label, $link['url']);
$row_title = $this->l($label, $link['url']);
}
if (empty($link['url'])) {
......
......@@ -15,6 +15,7 @@
use Drupal\Core\Datetime\DateFormatter;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Form\FormBuilderInterface;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
......@@ -173,13 +174,13 @@ public function overview() {
if ($message && isset($dblog->wid)) {
// Truncate link_text to 56 chars of message.
$log_text = Unicode::truncate(Xss::filter($message, array()), 56, TRUE, TRUE);
$message = $this->l($log_text, 'dblog.event', array('event_id' => $dblog->wid), array(
$message = $this->l($log_text, new Url('dblog.event', array('event_id' => $dblog->wid), array(
'attributes' => array(
// Provide a title for the link for useful hover hints.
'title' => Unicode::truncate(strip_tags($message), 256, TRUE, TRUE),
),
'html' => TRUE,
));
)));
}
$username = array(
'#theme' => 'username',
......
......@@ -9,6 +9,7 @@
use Drupal\Component\Utility\String;
use Drupal\Component\Utility\Xss;
use Drupal\Core\Url;
use Drupal\views\Views;
use Drupal\views\Tests\ViewTestData;
use Drupal\views\Tests\ViewUnitTestBase;
......@@ -60,12 +61,12 @@ public function testIntegration() {
// Setup a watchdog entry without tokens.
$entries[] = array(
'message' => $this->randomMachineName(),
'variables' => array('link' => \Drupal::l('Link', '<front>')),
'variables' => array('link' => \Drupal::l('Link', new Url('<front>'))),
);
// Setup a watchdog entry with one token.
$entries[] = array(
'message' => '@token1',
'variables' => array('@token1' => $this->randomMachineName(), 'link' => \Drupal::l('Link', '<front>')),
'variables' => array('@token1' => $this->randomMachineName(), 'link' => \Drupal::l('Link', new Url('<front>'))),
);
// Setup a watchdog entry with two tokens.
$entries[] = array(
......@@ -75,7 +76,7 @@ public function testIntegration() {
'variables' => array(
'@token1' => $this->randomMachineName(),
'!token2' => $this->randomMachineName(),
'link' => \Drupal::l('<object>Link</object>', '<front>'),
'link' => \Drupal::l('<object>Link</object>', new Url('<front>')),
),
);
$logger_factory = $this->container->get('logger.factory');
......
......@@ -10,6 +10,7 @@
use Drupal\Core\Extension\Extension;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Url;
/*
* Load all public Field API functions. Drupal currently has no
......@@ -87,7 +88,7 @@ function field_help($route_name, RouteMatchInterface $route_match) {
if (isset($info[$provider]['name'])) {
$display = $info[$provider]['name'];
if (\Drupal::moduleHandler()->implementsHook($provider, 'help')) {
$items[] = \Drupal::l($display, 'help.page', array('name' => $provider));
$items[] = \Drupal::l($display, new Url('help.page', array('name' => $provider)));
}
else {
$items[] = $display;
......
......@@ -112,7 +112,7 @@ public function buildRow(EntityInterface $field_storage) {
$usage = array();
foreach ($field_storage->getBundles() as $bundle) {
if ($route_info = FieldUI::getOverviewRouteInfo($field_storage->entity_type, $bundle)) {
$usage[] = \Drupal::linkGenerator()->generateFromUrl($this->bundles[$field_storage->entity_type][$bundle]['label'], $route_info);
$usage[] = \Drupal::l($this->bundles[$field_storage->entity_type][$bundle]['label'], $route_info);
}
else {
$usage[] = $this->bundles[$field_storage->entity_type][$bundle]['label'];
......
......@@ -10,6 +10,7 @@
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\Element\RenderElement;
use Drupal\Core\Render\Element;
use Drupal\Core\Url;
/**
* Provides a text format render element.
......@@ -179,7 +180,7 @@ public static function processFormat(&$element, FormStateInterface $form_state,
$element['format']['help'] = array(
'#type' => 'container',
'#attributes' => array('class' => array('filter-help')),
'#markup' => \Drupal::l(t('About text formats'), 'filter.tips_all', array(), array('attributes' => array('target' => '_blank'))),
'#markup' => \Drupal::l(t('About text formats'), new Url('filter.tips_all', array(), array('attributes' => array('target' => '_blank')))),
'#weight' => 0,
);
......
......@@ -9,6 +9,7 @@
use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
use Drupal\Component\Utility\Xss;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Url;
use Drupal\Component\Utility\String;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Routing\RouteMatchInterface;
......@@ -536,11 +537,11 @@ function template_preprocess_forums(&$variables) {
if ($variables['tid'] != $topic->forum_tid) {
$variables['topics'][$id]->moved = TRUE;
$variables['topics'][$id]->title = String::checkPlain($topic->getTitle());
$variables['topics'][$id]->message = \Drupal::l(t('This topic has been moved'), 'forum.page', ['taxonomy_term' => $topic->forum_tid]);
$variables['topics'][$id]->message = \Drupal::l(t('This topic has been moved'), new Url('forum.page', ['taxonomy_term' => $topic->forum_tid]));
}
else {
$variables['topics'][$id]->moved = FALSE;
$variables['topics'][$id]->title_link = \Drupal::linkGenerator()->generateFromUrl($topic->getTitle(), $topic->urlInfo());
$variables['topics'][$id]->title_link = \Drupal::l($topic->getTitle(), $topic->urlInfo());
$variables['topics'][$id]->message = '';
}
$forum_submitted = array('#theme' => 'forum_submitted', '#topic' => (object) array(
......
......@@ -8,6 +8,7 @@
namespace Drupal\forum\Form;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Drupal\taxonomy\TermForm;
/**
......@@ -81,7 +82,7 @@ public function save(array $form, FormStateInterface $form_state) {
$route_name = $this->urlStub == 'container' ? 'forum.edit_container' : 'forum.edit_forum';
$route_parameters = ['taxonomy_term' => $term->id()];
$link = \Drupal::l($this->t('Edit'), $route_name, $route_parameters);
$link = $this->l($this->t('Edit'), new Url($route_name, $route_parameters));
switch ($status) {
case SAVED_NEW:
drupal_set_message($this->t('Created new @type %term.', array('%term' => $term->getName(), '@type' => $this->forumFormType)));
......
......@@ -9,6 +9,7 @@
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Drupal\Component\Utility\String;
......@@ -83,7 +84,7 @@ protected function helpLinksAsList() {
$output = '<div class="clearfix"><div class="help-items"><ul>';
$i = 0;
foreach ($modules as $module => $name) {
$output .= '<li>' . $this->l($name, 'help.page', array('name' => $module)) . '</li>';
$output .= '<li>' . $this->l($name, new Url('help.page', array('name' => $module))) . '</li>';
if (($i + 1) % $break == 0 && ($i + 1) != $count) {
$output .= '</ul></div><div class="help-items' . ($i + 1 == $break * 3 ? ' help-items-last' : '') . '"><ul>';
}
......
......@@ -66,7 +66,7 @@ function template_preprocess_link_formatter_link_separate(&$variables) {
}
if (!$variables['url']->isExternal()) {
$variables['link'] = \Drupal::linkGenerator()->generateFromUrl($variables['url_title'], $variables['url']);
$variables['link'] = \Drupal::l($variables['url_title'], $variables['url']);
}
else {
$variables['link'] = l($variables['url_title'], $variables['url']->getPath(), $variables['url']->getOptions());
......
......@@ -5,6 +5,7 @@
* Install, update, and uninstall functions for the Locale module.
*/
use Drupal\Core\Url;
use Drupal\Core\Language\Language;