Issue #2329763 by lauriii, Jens-0, Cottser, Sutharsan: Move links classes from preprocess to templates.
parent
5f47f20c29
commit
45ebdf02cc
|
@ -984,10 +984,7 @@ function template_preprocess_links(&$variables) {
|
||||||
'url' => NULL,
|
'url' => NULL,
|
||||||
);
|
);
|
||||||
|
|
||||||
$li_attributes = array('class' => array());
|
$li_attributes = array();
|
||||||
// Use the array key as class name.
|
|
||||||
$li_attributes['class'][] = drupal_html_class($key);
|
|
||||||
|
|
||||||
$keys = ['title', 'url'];
|
$keys = ['title', 'url'];
|
||||||
$link_element = array(
|
$link_element = array(
|
||||||
'#type' => 'link',
|
'#type' => 'link',
|
||||||
|
@ -1043,7 +1040,7 @@ function template_preprocess_links(&$variables) {
|
||||||
$item['attributes'] = new Attribute($li_attributes);
|
$item['attributes'] = new Attribute($li_attributes);
|
||||||
|
|
||||||
// Add the item to the list of links.
|
// Add the item to the list of links.
|
||||||
$variables['links'][] = $item;
|
$variables['links'][$key] = $item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -271,11 +271,11 @@ class FunctionsTest extends WebTestBase {
|
||||||
$expected_links .= '<ul id="somelinks">';
|
$expected_links .= '<ul id="somelinks">';
|
||||||
$expected_links .= '<li class="a-link"><a href="' . Url::fromUri('base://a/link')->toString() . '">' . String::checkPlain('A <link>') . '</a></li>';
|
$expected_links .= '<li class="a-link"><a href="' . Url::fromUri('base://a/link')->toString() . '">' . String::checkPlain('A <link>') . '</a></li>';
|
||||||
$expected_links .= '<li class="plain-text"><span class="a/class">' . String::checkPlain('Plain "text"') . '</span></li>';
|
$expected_links .= '<li class="plain-text"><span class="a/class">' . String::checkPlain('Plain "text"') . '</span></li>';
|
||||||
$expected_links .= '<li class="front-page" data-drupal-link-system-path="<front>"><a href="' . _url('<front>') . '" data-drupal-link-system-path="<front>">' . String::checkPlain('Front page') . '</a></li>';
|
$expected_links .= '<li data-drupal-link-system-path="<front>" class="front-page"><a href="' . _url('<front>') . '" data-drupal-link-system-path="<front>">' . String::checkPlain('Front page') . '</a></li>';
|
||||||
$expected_links .= '<li class="router-test" data-drupal-link-system-path="router_test/test1"><a href="' . \Drupal::urlGenerator()->generate('router_test.1') . '" data-drupal-link-system-path="router_test/test1">' . String::checkPlain('Test route') . '</a></li>';
|
$expected_links .= '<li data-drupal-link-system-path="router_test/test1" class="router-test"><a href="' . \Drupal::urlGenerator()->generate('router_test.1') . '" data-drupal-link-system-path="router_test/test1">' . String::checkPlain('Test route') . '</a></li>';
|
||||||
$query = array('key' => 'value');
|
$query = array('key' => 'value');
|
||||||
$encoded_query = String::checkPlain(Json::encode($query));
|
$encoded_query = String::checkPlain(Json::encode($query));
|
||||||
$expected_links .= '<li class="query-test" data-drupal-link-query="'.$encoded_query.'" data-drupal-link-system-path="router_test/test1"><a href="' . \Drupal::urlGenerator()->generate('router_test.1', $query) . '" data-drupal-link-query="'.$encoded_query.'" data-drupal-link-system-path="router_test/test1">' . String::checkPlain('Query test route') . '</a></li>';
|
$expected_links .= '<li data-drupal-link-query="'.$encoded_query.'" data-drupal-link-system-path="router_test/test1" class="query-test"><a href="' . \Drupal::urlGenerator()->generate('router_test.1', $query) . '" data-drupal-link-query="'.$encoded_query.'" data-drupal-link-system-path="router_test/test1">' . String::checkPlain('Query test route') . '</a></li>';
|
||||||
$expected_links .= '</ul>';
|
$expected_links .= '</ul>';
|
||||||
$expected = $expected_heading . $expected_links;
|
$expected = $expected_heading . $expected_links;
|
||||||
$this->assertThemeOutput('links', $variables, $expected);
|
$this->assertThemeOutput('links', $variables, $expected);
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
* not be passed through \Drupal\Component\Utility\String::checkPlain().
|
* not be passed through \Drupal\Component\Utility\String::checkPlain().
|
||||||
* - attributes: (optional) HTML attributes for the anchor, or for the <span>
|
* - attributes: (optional) HTML attributes for the anchor, or for the <span>
|
||||||
* tag if no 'href' is supplied.
|
* tag if no 'href' is supplied.
|
||||||
|
* - link_key: The link CSS class.
|
||||||
* - heading: (optional) A heading to precede the links.
|
* - heading: (optional) A heading to precede the links.
|
||||||
* - text: The heading text.
|
* - text: The heading text.
|
||||||
* - level: The heading level (e.g. 'h2', 'h3').
|
* - level: The heading level (e.g. 'h2', 'h3').
|
||||||
|
@ -44,8 +45,8 @@
|
||||||
{%- endif -%}
|
{%- endif -%}
|
||||||
{%- endif -%}
|
{%- endif -%}
|
||||||
<ul{{ attributes }}>
|
<ul{{ attributes }}>
|
||||||
{%- for item in links -%}
|
{%- for key, item in links -%}
|
||||||
<li{{ item.attributes }}>
|
<li{{ item.attributes.addClass(key|clean_class) }}>
|
||||||
{%- if item.link -%}
|
{%- if item.link -%}
|
||||||
{{ item.link }}
|
{{ item.link }}
|
||||||
{%- elseif item.text_attributes -%}
|
{%- elseif item.text_attributes -%}
|
||||||
|
|
Loading…
Reference in New Issue