diff --git a/core/includes/common.inc b/core/includes/common.inc
index 65aef09..aa64ae4 100644
--- a/core/includes/common.inc
+++ b/core/includes/common.inc
@@ -2916,6 +2916,13 @@ function drupal_pre_render_link($element) {
$element['#options']['attributes'] += $element['#attributes'];
}
+ // Merge the provided attributes on top of the default attributes
+ // provided by the element definition.
+ if (isset($element['#default_attributes'])) {
+ $element['#options'] += array('attributes' => array());
+ $element['#options']['attributes'] = NestedArray::mergeDeep($element['#default_attributes'], $element['#options']['attributes']);
+ }
+
// This #pre_render callback can be invoked from inside or outside of a Form
// API context, and depending on that, a HTML ID may be already set in
// different locations. #options should have precedence over Form API's #id.
diff --git a/core/includes/theme.inc b/core/includes/theme.inc
index e44f13d..e763ed3 100644
--- a/core/includes/theme.inc
+++ b/core/includes/theme.inc
@@ -1787,18 +1787,6 @@ function template_preprocess_feed_icon(&$variables) {
}
/**
- * 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 '
' . l(t('More'), $variables['url'], array('attributes' => array('title' => $variables['title']))) . '
';
-}
-
-/**
* Returns HTML for an indentation div; used for drag and drop tables.
*
* @param $variables
@@ -2580,9 +2568,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',
diff --git a/core/modules/aggregator/src/Plugin/Block/AggregatorFeedBlock.php b/core/modules/aggregator/src/Plugin/Block/AggregatorFeedBlock.php
index 5fdc33a..bc60ba4 100644
--- a/core/modules/aggregator/src/Plugin/Block/AggregatorFeedBlock.php
+++ b/core/modules/aggregator/src/Plugin/Block/AggregatorFeedBlock.php
@@ -154,9 +154,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();
diff --git a/core/modules/forum/src/Plugin/Block/ForumBlockBase.php b/core/modules/forum/src/Plugin/Block/ForumBlockBase.php
index d7dfc31..fc9881b 100644
--- a/core/modules/forum/src/Plugin/Block/ForumBlockBase.php
+++ b/core/modules/forum/src/Plugin/Block/ForumBlockBase.php
@@ -25,9 +25,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' => t('Read the latest forum topics.')),
);
}
return $elements;
diff --git a/core/modules/system/css/system.theme.css b/core/modules/system/css/system.theme.css
index c8908b5..7e9f511 100644
--- a/core/modules/system/css/system.theme.css
+++ b/core/modules/system/css/system.theme.css
@@ -130,7 +130,7 @@ abbr.ajax-changed {
}
/**
- * Markup generated by theme_more_link().
+ * Markup generated by #type 'link'.
*/
.more-link {
display: block;
diff --git a/core/modules/system/src/Tests/Common/RenderElementTypesTest.php b/core/modules/system/src/Tests/Common/RenderElementTypesTest.php
index 15a1904..7ca1bc6 100644
--- a/core/modules/system/src/Tests/Common/RenderElementTypesTest.php
+++ b/core/modules/system/src/Tests/Common/RenderElementTypesTest.php
@@ -20,7 +20,7 @@ class RenderElementTypesTest extends DrupalUnitTestBase {
*
* @var array
*/
- public static $modules = array('system');
+ public static $modules = array('system', 'router_test');
public static function getInfo() {
return array(
@@ -33,6 +33,8 @@ public static function getInfo() {
protected function setUp() {
parent::setUp();
$this->installConfig(array('system'));
+ $this->installSchema('system', array('router'));
+ \Drupal::service('router.builder')->rebuild();
}
/**
@@ -107,4 +109,81 @@ function testHtmlTag() {
), "title test\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' => '//a[@href="http://drupal.org" and @class="more-link" 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' => '//a[@href="http://drupal.org" and @class="more-link" and text()="More Titles"]',
+ ),
+ array(
+ 'name' => "#type 'more_link' anchor tag generation with extra classes",
+ 'value' => array(
+ '#type' => 'more_link',
+ '#href' => 'http://drupal.org',
+ '#attributes' => array(
+ 'title' => 'description',
+ 'class' => array('drupal', 'test'),
+ ),
+ ),
+ 'expected' => '//a[@href="http://drupal.org" and @title="description" and contains(@class, "more-link") and contains(@class, "drupal") and contains(@class, "test") and text()="More"]',
+ ),
+ array(
+ 'name' => "#type 'more_link' anchor tag with a relative path",
+ 'value' => array(
+ '#type' => 'more_link',
+ '#href' => 'a/link',
+ ),
+ 'expected' => '//a[@href="' . url('a/link') . '" and @class="more-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' => '//a[@href="' . \Drupal::urlGenerator()->generate('router_test.1') . '" and @class="more-link" 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' => '//a[@href="' . url('admin/content', array('absolute' => TRUE)) . '" and @class="more-link" and text()="More"]',
+ ),
+ array(
+ 'name' => "#type 'more_link' anchor tag to the front page",
+ 'value' => array(
+ '#type' => 'more_link',
+ '#href' => '',
+ ),
+ 'expected' => '//a[@href="' . url('') . '" and @class="more-link" 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().');
+ }
+ }
+
}
diff --git a/core/modules/system/system.module b/core/modules/system/system.module
index 8feb47b..5402a70 100644
--- a/core/modules/system/system.module
+++ b/core/modules/system/system.module
@@ -576,6 +576,11 @@ function system_element_info() {
$types['link'] = array(
'#pre_render' => array('drupal_pre_render_link'),
);
+ // A "more" link, like those used in blocks.
+ $types['more_link'] = $types['link'] + array(
+ '#title' => t('More'),
+ '#default_attributes' => array('class' => array('more-link')),
+ );
$types['fieldset'] = array(
'#value' => NULL,
'#process' => array('form_process_group', 'ajax_process_form'),
diff --git a/core/modules/system/tests/modules/theme_test/src/EventSubscriber/ThemeTestSubscriber.php b/core/modules/system/tests/modules/theme_test/src/EventSubscriber/ThemeTestSubscriber.php
index 0cdf668..a02be18 100644
--- a/core/modules/system/tests/modules/theme_test/src/EventSubscriber/ThemeTestSubscriber.php
+++ b/core/modules/system/tests/modules/theme_test/src/EventSubscriber/ThemeTestSubscriber.php
@@ -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);
}