Commit 1f54a150 authored by TravisCarden's avatar TravisCarden

By TravisCarden: Replaced l() with routing based URL generation API per #2346779.

parent bf20e7b4
......@@ -61,9 +61,7 @@
* arbitrary unique identifier. The corresponding multimensional array
* describing the link may contain the following key-value pairs:
* - #text: The link text.
* - #path: The link path.
* - #options: (optional) An associative array of additional options
* used by the l() function.
* - #url: The link url as a \Drupal\Core\Url object.
* - #weight: (optional) A floating point number used to sort the list
* of items before being output. Lower numbers appear before higher
* numbers.
......@@ -85,7 +83,7 @@ function hook_checklistapi_checklist_info() {
'#title' => t('Example item 1'),
'example_link' => array(
'#text' => t('Example.com'),
'#path' => 'http://www.example.com/',
'#url' => \Drupal\Core\Url::fromUri('http://www.example.com/'),
),
),
'example_item_2' => array(
......
......@@ -222,19 +222,21 @@ function checklistapi_theme() {
function template_preprocess_checklistapi_compact_link(array &$variables) {
if (checklistapi_compact_mode()) {
$text = t('Show item descriptions');
$path = Url::fromRoute('<current>') . '/compact/off';
$mode = 'off';
$title = t('Expand layout to include item descriptions.');
}
else {
$text = t('Hide item descriptions');
$path = Url::fromRoute('<current>') . '/compact/on';
$mode = 'on';
$title = t('Compress layout by hiding item descriptions.');
}
$variables['link'] = l($text, $path, array(
'attributes' => array(
'title' => $title,
),
'query' => drupal_get_destination(),
));
$current_route = \Drupal::routeMatch()->getRouteName();
$route_name = "{$current_route}.compact";
$route_parameters = array('mode' => $mode);
$options = array('query' => drupal_get_destination());
$url = Url::fromRoute($route_name, $route_parameters, $options)
->setOption('attributes', array('title' => $title));
$variables['link'] = \Drupal::l($text, $url);
}
......@@ -10,6 +10,7 @@ namespace Drupal\checklistapi\Controller;
use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Routing\Route;
use Drupal\Core\Url;
/**
* Controller for Checklist API.
......@@ -48,7 +49,7 @@ class ChecklistapiController extends ControllerBase {
$checklist = checklistapi_checklist_load($id);
$row = array();
$row[] = array(
'data' => ($checklist->userHasAccess()) ? l($checklist->title, $checklist->path) : drupal_placeholder($checklist->title),
'data' => ($checklist->userHasAccess()) ? \Drupal::l($checklist->title, $checklist->getUrl()) : drupal_placeholder($checklist->title),
'title' => (!empty($checklist->description)) ? $checklist->description : '',
);
$row[] = t('@completed of @total (@percent%)', array(
......
......@@ -11,6 +11,7 @@ use Drupal\Component\Utility\Xss;
use Drupal\Core\Form\FormInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\Element;
use Drupal\Core\Url;
/**
* Provides a checklist form.
......@@ -116,8 +117,7 @@ class ChecklistapiChecklistForm implements FormInterface {
$links = array();
foreach (Element::children($item) as $link_key) {
$link = &$item[$link_key];
$options = (!empty($link['#options']) && is_array($link['#options'])) ? $link['#options'] : array();
$links[] = l($link['#text'], $link['#path'], $options);
$links[] = \Drupal::l($link['#text'], Url::fromUri($link['#url']));
}
if (count($links)) {
$description .= '<div class="links">' . implode(' | ', $links) . '</div>';
......
......@@ -4,7 +4,7 @@
* Default theme implementation of a checklist compact link.
*
* Available variables:
* - link: The link, already formatted by l().
* - link: The link, already formatted by \Drupal::l().
*
* @see template_preprocess_checklistapi_compact_link()
*
......
......@@ -45,17 +45,17 @@ class ChecklistapiModuleTest extends UnitTestCase {
'#weight' => -1,
'link_three' => array(
'#text' => 'Link three',
'#path' => 'http://example.com/three',
'#url' => Url::fromUri('http://example.com/three'),
'#weight' => 3,
),
'link_two' => array(
'#text' => 'Link two',
'#path' => 'http://example.com/two',
'#url' => Url::fromUri('http://example.com/two'),
'#weight' => 2,
),
'link_one' => array(
'#text' => 'Link one',
'#path' => 'http://example.com/one',
'#url' => Url::fromUri('http://example.com/one'),
'#weight' => 1,
),
),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment