Commit 946aee4f authored by webchick's avatar webchick

Issue #2031301 by andypost, Cottser, xjm, mark.labrecque, mariacha1,...

Issue #2031301 by andypost, Cottser, xjm, mark.labrecque, mariacha1, joelpittet, robynlgreen, danquah, trogels, Eric_A, thedavidmeister, jenlampton: Replace theme_more_link() and replace with #type 'more_link'.
parent 3ad28727
......@@ -1518,18 +1518,6 @@ function template_preprocess_feed_icon(&$variables) {
$variables['attributes']['title'] = strip_tags($text);
}
/**
* Returns HTML for a "more" link, like those used in blocks.
*
* @param $variables
* An associative array containing:
* - url: The URL of the main page.
* - title: A descriptive verb for the link, like 'Read more'.
*/
function theme_more_link($variables) {
return '<div class="more-link">' . l(t('More'), $variables['url'], array('attributes' => array('title' => $variables['title']))) . '</div>';
}
/**
* Returns HTML for an indentation div; used for drag and drop tables.
*
......@@ -2348,9 +2336,6 @@ function drupal_common_theme() {
'variables' => array('url' => NULL, 'title' => NULL),
'template' => 'feed-icon',
),
'more_link' => array(
'variables' => array('url' => NULL, 'title' => NULL)
),
'progress_bar' => array(
'variables' => array('label' => NULL, 'percent' => NULL, 'message' => NULL),
'template' => 'progress-bar',
......
<?php
/**
* @file
* Contains \Drupal\Core\Render\Element\MoreLink.
*/
namespace Drupal\Core\Render\Element;
/**
* Provides a link render element.
*
* @RenderElement("more_link")
*/
class MoreLink extends Link {
/**
* {@inheritdoc}
*/
public function getInfo() {
$class = get_class($this);
$info = parent::getInfo();
return array(
'#title' => $this->t('More'),
'#theme_wrappers' => array(
'container' => array(
'#attributes' => array('class' => 'more-link'),
),
),
) + $info;
}
}
......@@ -163,9 +163,9 @@ public function build() {
$items = $this->itemStorage->loadMultiple($result);
$more_link = array(
'#theme' => 'more_link',
'#url' => 'aggregator/sources/' . $feed->id(),
'#title' => t("View this feed's recent news."),
'#type' => 'more_link',
'#href' => 'aggregator/sources/' . $feed->id(),
'#attributes' => array('title' => $this->t("View this feed's recent news.")),
);
$read_more = drupal_render($more_link);
$rendered_items = array();
......
......@@ -26,9 +26,9 @@ public function build() {
if ($node_title_list = node_title_list($result)) {
$elements['forum_list'] = $node_title_list;
$elements['forum_more'] = array(
'#theme' => 'more_link',
'#url' => 'forum',
'#title' => t('Read the latest forum topics.')
'#type' => 'more_link',
'#href' => 'forum',
'#attributes' => array('title' => $this->t('Read the latest forum topics.')),
);
}
return $elements;
......
......@@ -129,7 +129,7 @@ abbr.ajax-changed {
}
/**
* Markup generated by theme_more_link().
* Markup generated by #type 'more_link'.
*/
.more-link {
display: block;
......
......@@ -22,11 +22,13 @@ class RenderElementTypesTest extends DrupalUnitTestBase {
*
* @var array
*/
public static $modules = array('system');
public static $modules = array('system', 'router_test');
protected function setUp() {
parent::setUp();
$this->installConfig(array('system'));
$this->installSchema('system', array('router'));
\Drupal::service('router.builder')->rebuild();
}
/**
......@@ -101,4 +103,85 @@ function testHtmlTag() {
), "<title>title test</title>\n", "#type 'html_tag' title tag generation");
}
/**
* Tests system #type 'more_link'.
*/
function testMoreLink() {
$elements = array(
array(
'name' => "#type 'more_link' anchor tag generation without extra classes",
'value' => array(
'#type' => 'more_link',
'#href' => 'http://drupal.org',
),
'expected' => '//div[@class="more-link"]/a[@href="http://drupal.org" and text()="More"]',
),
array(
'name' => "#type 'more_link' anchor tag generation with different link text",
'value' => array(
'#type' => 'more_link',
'#href' => 'http://drupal.org',
'#title' => 'More Titles',
),
'expected' => '//div[@class="more-link"]/a[@href="http://drupal.org" and text()="More Titles"]',
),
array(
'name' => "#type 'more_link' anchor tag generation with attributes on wrapper",
'value' => array(
'#type' => 'more_link',
'#href' => 'http://drupal.org',
'#theme_wrappers' => array(
'container' => array(
'#attributes' => array(
'title' => 'description',
'class' => array('more-link', 'drupal', 'test'),
),
),
),
),
'expected' => '//div[@title="description" and contains(@class, "more-link") and contains(@class, "drupal") and contains(@class, "test")]/a[@href="http://drupal.org" and text()="More"]',
),
array(
'name' => "#type 'more_link' anchor tag with a relative path",
'value' => array(
'#type' => 'more_link',
'#href' => 'a/link',
),
'expected' => '//div[@class="more-link"]/a[@href="' . url('a/link') . '" and text()="More"]',
),
array(
'name' => "#type 'more_link' anchor tag with a route",
'value' => array(
'#type' => 'more_link',
'#route_name' => 'router_test.1',
'#route_parameters' => array(),
),
'expected' => '//div[@class="more-link"]/a[@href="' . \Drupal::urlGenerator()->generate('router_test.1') . '" and text()="More"]',
),
array(
'name' => "#type 'more_link' anchor tag with an absolute path",
'value' => array(
'#type' => 'more_link',
'#href' => 'admin/content',
'#options' => array('absolute' => TRUE),
),
'expected' => '//div[@class="more-link"]/a[@href="' . url('admin/content', array('absolute' => TRUE)) . '" and text()="More"]',
),
array(
'name' => "#type 'more_link' anchor tag to the front page",
'value' => array(
'#type' => 'more_link',
'#href' => '<front>',
),
'expected' => '//div[@class="more-link"]/a[@href="' . url('<front>') . '" and text()="More"]',
),
);
foreach($elements as $element) {
$xml = new \SimpleXMLElement(drupal_render($element['value']));
$result = $xml->xpath($element['expected']);
$this->assertTrue($result, '"' . $element['name'] . '" input rendered correctly by drupal_render().');
}
}
}
......@@ -43,9 +43,9 @@ public function onRequest(GetResponseEvent $event) {
// theme system is initialized this early, it is still capable of
// returning output and theming the page as a whole.
$more_link = array(
'#theme' => 'more_link',
'#url' => 'user',
'#title' => 'Themed output generated in a KernelEvents::REQUEST listener',
'#type' => 'more_link',
'#href' => 'user',
'#attributes' => array('title' => 'Themed output generated in a KernelEvents::REQUEST listener'),
);
$GLOBALS['theme_test_output'] = drupal_render($more_link);
}
......
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