Commit 660f2d0d authored by catch's avatar catch

Issue #1985470 by thedavidmeister: Remove theme_link().

parent cc7ca3ed
......@@ -1468,7 +1468,6 @@ function drupal_http_header_attributes(array $attributes = array()) {
* An HTML string containing a link to the given path.
*
* @see url()
* @see theme_link()
*/
function l($text, $path, array $options = array()) {
// Start building a structured representation of our link to be altered later.
......
......@@ -1641,25 +1641,6 @@ function theme_status_messages($variables) {
return $output;
}
/**
* Returns HTML for a link.
*
* This is a wrapper around l() to allow for more flexible link themeing.
*
* Where performance is more important than theme flexibility, Drupal code that
* outputs a link should call the l() function directly, as #theme 'link'
* implementations have a measurable performance impact.
*
* @param $variables
* An associative array containing the keys 'text', 'path', and 'options'.
* See the l() function for information about these variables.
*
* @see l()
*/
function theme_link($variables) {
return l($variables['text'], $variables['path'], $variables['options']);
}
/**
* Returns HTML for a set of links.
*
......@@ -3108,9 +3089,6 @@ function drupal_common_theme() {
'status_messages' => array(
'variables' => array('display' => NULL),
),
'link' => array(
'variables' => array('text' => NULL, 'path' => NULL, 'options' => array()),
),
'links' => array(
'variables' => array('links' => array(), 'attributes' => array('class' => array('links')), 'heading' => array()),
),
......
......@@ -256,7 +256,7 @@ function contextual_pre_render_links($element) {
$items += menu_contextual_links($module, $args[0], $args[1]);
}
// Transform contextual links into parameters suitable for theme_link().
// Transform contextual links into parameters suitable for theme_links().
$links = array();
foreach ($items as $class => $item) {
$class = drupal_html_class($class);
......
......@@ -104,11 +104,11 @@ function testLanguageLinkActiveClass() {
$edit = array('language_interface[enabled][language-url]' => '1');
$this->drupalPost('admin/config/regional/language/detection', $edit, t('Save settings'));
$function_name = 'l()';
$function_name = '#type link';
// Test links generated by l() on an English page.
$current_language = 'English';
$this->drupalGet('language_test/l-active-class');
$this->drupalGet('language_test/type-link-active-class');
// Language code 'none' link should be active.
$langcode = 'none';
......@@ -127,47 +127,7 @@ function testLanguageLinkActiveClass() {
// Test links generated by l() on a French page.
$current_language = 'French';
$this->drupalGet('fr/language_test/l-active-class');
// Language code 'none' link should be active.
$langcode = 'none';
$links = $this->xpath('//a[@id = :id and contains(@class, :class)]', array(':id' => 'no_lang_link', ':class' => 'active'));
$this->assertTrue(isset($links[0]), t('A link generated by :function to the current :language page with langcode :langcode is marked active.', array(':function' => $function_name, ':language' => $current_language, ':langcode' => $langcode)));
// Language code 'en' link should not be active.
$langcode = 'en';
$links = $this->xpath('//a[@id = :id and not(contains(@class, :class))]', array(':id' => 'en_link', ':class' => 'active'));
$this->assertTrue(isset($links[0]), t('A link generated by :function to the current :language page with langcode :langcode is NOT marked active.', array(':function' => $function_name, ':language' => $current_language, ':langcode' => $langcode)));
// Language code 'fr' link should be active.
$langcode = 'fr';
$links = $this->xpath('//a[@id = :id and contains(@class, :class)]', array(':id' => 'fr_link', ':class' => 'active'));
$this->assertTrue(isset($links[0]), t('A link generated by :function to the current :language page with langcode :langcode is marked active.', array(':function' => $function_name, ':language' => $current_language, ':langcode' => $langcode)));
$function_name = "theme('link')";
// Test links generated by theme('link') on an English page.
$current_language = 'English';
$this->drupalGet('language_test/theme-link-active-class');
// Language code 'none' link should be active.
$langcode = 'none';
$links = $this->xpath('//a[@id = :id and contains(@class, :class)]', array(':id' => 'no_lang_link', ':class' => 'active'));
$this->assertTrue(isset($links[0]), t('A link generated by :function to the current :language page with langcode :langcode is marked active.', array(':function' => $function_name, ':language' => $current_language, ':langcode' => $langcode)));
// Language code 'en' link should be active.
$langcode = 'en';
$links = $this->xpath('//a[@id = :id and contains(@class, :class)]', array(':id' => 'en_link', ':class' => 'active'));
$this->assertTrue(isset($links[0]), t('A link generated by :function to the current :language page with langcode :langcode is marked active.', array(':function' => $function_name, ':language' => $current_language, ':langcode' => $langcode)));
// Language code 'fr' link should not be active.
$langcode = 'fr';
$links = $this->xpath('//a[@id = :id and not(contains(@class, :class))]', array(':id' => 'fr_link', ':class' => 'active'));
$this->assertTrue(isset($links[0]), t('A link generated by :function to the current :language page with langcode :langcode is NOT marked active.', array(':function' => $function_name, ':language' => $current_language, ':langcode' => $langcode)));
// Test links generated by theme('link') on a French page.
$current_language = 'French';
$this->drupalGet('fr/language_test/theme-link-active-class');
$this->drupalGet('fr/language_test/type-link-active-class');
// Language code 'none' link should be active.
$langcode = 'none';
......
language_test_l_active_class:
pattern: '/language_test/l-active-class'
pattern: '/language_test/type-link-active-class'
defaults:
_content: '\Drupal\language_test\Controller\LanguageTestController::lActiveClass'
requirements:
_access: 'TRUE'
language_test_theme_link_active_class:
pattern: '/language_test/theme-link-active-class'
defaults:
_content: '\Drupal\language_test\Controller\LanguageTestController::themeLinkActiveClass'
_content: '\Drupal\language_test\Controller\LanguageTestController::typeLinkActiveClass'
requirements:
_access: 'TRUE'
......
......@@ -44,53 +44,9 @@ public static function create(ContainerInterface $container) {
/**
* Returns links to the current page with different langcodes.
*
* Using #theme causes these links to be rendered with theme_link().
* Using #type 'link' causes these links to be rendered with l().
*/
public function themeLinkActiveClass() {
// We assume that 'en' and 'fr' have been configured.
$languages = language_list();
return array(
'no_language' => array(
'#theme' => 'link',
'#text' => t('Link to the current path with no langcode provided.'),
'#path' => current_path(),
'#options' => array(
'attributes' => array(
'id' => 'no_lang_link',
),
),
),
'fr' => array(
'#theme' => 'link',
'#text' => t('Link to a French version of the current path.'),
'#path' => current_path(),
'#options' => array(
'language' => $languages['fr'],
'attributes' => array(
'id' => 'fr_link',
),
),
),
'en' => array(
'#theme' => 'link',
'#text' => t('Link to an English version of the current path.'),
'#path' => current_path(),
'#options' => array(
'language' => $languages['en'],
'attributes' => array(
'id' => 'en_link',
),
),
),
);
}
/**
* Returns links to the current page with different langcodes.
*
* Using #type causes these links to be rendered with l().
*/
public function lActiveClass() {
public function typeLinkActiveClass() {
// We assume that 'en' and 'fr' have been configured.
$languages = language_list();
return array(
......
......@@ -156,7 +156,7 @@ public function viewElements(EntityInterface $entity, $langcode, array $items) {
// If the title field value is available, use it for the link text.
if (empty($settings['url_only']) && !empty($item['title'])) {
// Unsanitizied token replacement here because $options['html'] is FALSE
// by default in theme_link().
// by default in l().
$link_title = \Drupal::token()->replace($item['title'], array($entity->entityType() => $entity), array('sanitize' => FALSE, 'clear' => TRUE));
}
......
......@@ -50,7 +50,7 @@ public function viewElements(EntityInterface $entity, $langcode, array $items) {
// If the link text field value is available, use it for the text.
if (empty($settings['url_only']) && !empty($item['title'])) {
// Unsanitized token replacement here because $options['html'] is FALSE
// by default in theme_link().
// by default in l().
$link_title = \Drupal::token()->replace($item['title'], array($entity->entityType() => $entity), array('sanitize' => FALSE, 'clear' => TRUE));
}
......
......@@ -320,7 +320,7 @@ function testLinkFormatter() {
// Verify that the link is output according to the formatter settings.
// Not using generatePermutations(), since that leads to 32 cases, which
// would not test actual link field formatter functionality but rather
// theme_link() and options/attributes. Only 'url_plain' has a dependency on
// l() and options/attributes. Only 'url_plain' has a dependency on
// 'url_only', so we have a total of ~10 cases.
$options = array(
'trim_length' => array(NULL, 6),
......
......@@ -39,19 +39,19 @@ function testLinkXSS() {
$sanitized_path = check_url(url($path));
$this->assertTrue(strpos($link, $sanitized_path) !== FALSE, format_string('XSS attack @path was filtered by l().', array('@path' => $path)));
// Test #theme.
// Test #type 'link'.
$link_array = array(
'#theme' => 'link',
'#text' => $this->randomName(),
'#path' => $path,
'#type' => 'link',
'#title' => $this->randomName(),
'#href' => $path,
);
$theme_link = drupal_render($link_array);
$type_link = drupal_render($link_array);
$sanitized_path = check_url(url($path));
$this->assertTrue(strpos($theme_link, $sanitized_path) !== FALSE, format_string('XSS attack @path was filtered by #theme', array('@path' => $path)));
$this->assertTrue(strpos($type_link, $sanitized_path) !== FALSE, format_string('XSS attack @path was filtered by #theme', array('@path' => $path)));
}
/**
* Tests for active class in links produced by l() and theme_link() functions.
* Tests for active class in links produced by l() and #type 'link'.
*/
function testLinkActiveClass() {
$options_no_query = array();
......@@ -68,8 +68,8 @@ function testLinkActiveClass() {
),
);
// Test l().
$path = 'common-test/l-active-class';
// Test #type link.
$path = 'common-test/type-link-active-class';
$this->drupalGet($path, $options_no_query);
$links = $this->xpath('//a[@href = :href and contains(@class, :class)]', array(':href' => url($path, $options_no_query), ':class' => 'active'));
......@@ -87,30 +87,10 @@ function testLinkActiveClass() {
$links = $this->xpath('//a[@href = :href and not(contains(@class, :class))]', array(':href' => url($path, $options_no_query), ':class' => 'active'));
$this->assertTrue(isset($links[0]), 'A link generated by l() to the current page without a query string when the current page has a query string is not marked active.');
// Test #theme.
$path = 'common-test/theme-link-active-class';
$this->drupalGet($path, $options_no_query);
$links = $this->xpath('//a[@href = :href and contains(@class, :class)]', array(':href' => url($path, $options_no_query), ':class' => 'active'));
$this->assertTrue(isset($links[0]), 'A link generated by #theme to the current page is marked active.');
$links = $this->xpath('//a[@href = :href and not(contains(@class, :class))]', array(':href' => url($path, $options_query), ':class' => 'active'));
$this->assertTrue(isset($links[0]), 'A link generated by #theme to the current page with a query string when the current page has no query string is not marked active.');
$this->drupalGet($path, $options_query);
$links = $this->xpath('//a[@href = :href and contains(@class, :class)]', array(':href' => url($path, $options_query), ':class' => 'active'));
$this->assertTrue(isset($links[0]), 'A link generated by #theme to the current page with a query string that matches the current query string is marked active.');
$links = $this->xpath('//a[@href = :href and contains(@class, :class)]', array(':href' => url($path, $options_query_reverse), ':class' => 'active'));
$this->assertTrue(isset($links[0]), 'A link generated by #theme to the current page with a query string that has matching parameters to the current query string but in a different order is marked active.');
$links = $this->xpath('//a[@href = :href and not(contains(@class, :class))]', array(':href' => url($path, $options_no_query), ':class' => 'active'));
$this->assertTrue(isset($links[0]), 'A link generated by #theme to the current page without a query string when the current page has a query string is not marked active.');
}
/**
* Tests for custom class in links produced by l() and theme_link() functions.
* Tests for custom class in links produced by l() and #type 'link'.
*/
function testLinkCustomClass() {
// Test l().
......@@ -118,20 +98,20 @@ function testLinkCustomClass() {
$link_l = l($this->randomName(), current_path(), array('attributes' => array('class' => array($class_l))));
$this->assertTrue($this->hasClass($link_l, $class_l), format_string('Custom class @class is present on link when requested by l()', array('@class' => $class_l)));
// Test #theme.
// Test #type.
$class_theme = $this->randomName();
$theme_link = array(
'#theme' => 'link',
'#text' => $this->randomName(),
'#path' => current_path(),
$type_link = array(
'#type' => 'link',
'#title' => $this->randomName(),
'#href' => current_path(),
'#options' => array(
'attributes' => array(
'class' => array($class_theme),
),
),
);
$link_theme = drupal_render($theme_link);
$this->assertTrue($this->hasClass($link_theme, $class_theme), format_string('Custom class @class is present on link when requested by #theme', array('@class' => $class_theme)));
$link_theme = drupal_render($type_link);
$this->assertTrue($this->hasClass($link_theme, $class_theme), format_string('Custom class @class is present on link when requested by #type', array('@class' => $class_theme)));
}
/**
......@@ -147,22 +127,22 @@ function testLinkRenderArrayText() {
$this->assertEqual($l_renderable_text, $l);
// Test a themed link with plain text 'text'.
$theme_link_plain_array = array(
'#theme' => 'link',
'#text' => 'foo',
'#path' => 'http://drupal.org',
$type_link_plain_array = array(
'#type' => 'link',
'#title' => 'foo',
'#href' => 'http://drupal.org',
);
$theme_link_plain = drupal_render($theme_link_plain_array);
$this->assertEqual($theme_link_plain, $l);
$type_link_plain = drupal_render($type_link_plain_array);
$this->assertEqual($type_link_plain, $l);
// Build a themed link with renderable 'text'.
$theme_link_nested_array = array(
'#theme' => 'link',
'#text' => array('#markup' => 'foo'),
'#path' => 'http://drupal.org',
$type_link_nested_array = array(
'#type' => 'link',
'#title' => array('#markup' => 'foo'),
'#href' => 'http://drupal.org',
);
$theme_link_nested = drupal_render($theme_link_nested_array);
$this->assertEqual($theme_link_nested, $l);
$type_link_nested = drupal_render($type_link_nested_array);
$this->assertEqual($type_link_nested, $l);
}
/**
......
common_test_l_active_class:
pattern: '/common-test/l-active-class'
pattern: '/common-test/type-link-active-class'
defaults:
_content: '\Drupal\common_test\Controller\CommonTestController::lActiveClass'
_content: '\Drupal\common_test\Controller\CommonTestController::typeLinkActiveClass'
requirements:
_access: 'TRUE'
common_test_theme_link_active_class:
pattern: '/common-test/theme-link-active-class'
defaults:
_content: '\Drupal\common_test\Controller\CommonTestController::themeLinkActiveClass'
requirements:
_access: 'TRUE'
......@@ -25,9 +25,9 @@ public static function create(ContainerInterface $container) {
/**
* Returns links to the current page, with and without query strings.
*
* Using #type causes these links to be rendered with l().
* Using #type 'link' causes these links to be rendered with l().
*/
public function lActiveClass() {
public function typeLinkActiveClass() {
return array(
'no_query' => array(
'#type' => 'link',
......@@ -59,41 +59,4 @@ public function lActiveClass() {
);
}
/**
* Returns links to the current page, with and without query strings.
*
* Using #theme causes these links to be rendered with theme_link().
*/
public function themeLinkActiveClass() {
return array(
'no_query' => array(
'#theme' => 'link',
'#text' => t('Link with no query string'),
'#path' => current_path(),
),
'with_query' => array(
'#theme' => 'link',
'#text' => t('Link with a query string'),
'#path' => current_path(),
'#options' => array(
'query' => array(
'foo' => 'bar',
'one' => 'two',
),
),
),
'with_query_reversed' => array(
'#theme' => 'link',
'#text' => t('Link with the same query string in reverse order'),
'#path' => current_path(),
'#options' => array(
'query' => array(
'one' => 'two',
'foo' => 'bar',
),
),
),
);
}
}
......@@ -580,7 +580,7 @@ function hook_views_preview_info_alter(array &$rows, ViewExecutable $view) {
* @param array $links
* A renderable array of links which will be displayed at the top of the
* view edit form. Each entry will be in a form suitable for
* '#theme' => 'link'.
* '#theme' => 'links'.
* @param \Drupal\views\ViewExecutable $view
* The view object being edited.
* @param string $display_id
......
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