Commit 8c38be01 authored by alexpott's avatar alexpott
Browse files

Issue #2254153 by crowdcg, davidhernandez, joelpittet, mortendk, mdrummond,...

Issue #2254153 by crowdcg, davidhernandez, joelpittet, mortendk, mdrummond, cilefen, LewisNyman: Move node classes out of preprocess and into templates.
parent d63702cf
......@@ -177,26 +177,26 @@ public function testContentTypeDirLang() {
// Check if English node does not have lang tag.
$this->drupalGet('node/' . $nodes['en']->id());
$pattern = '|class="[^"]*node[^"]*"[^<>]*lang="en"|';
$this->assertNoPattern($pattern, 'The lang tag has not been assigned to the English node.');
$element = $this->cssSelect('article.node[lang="en"]');
$this->assertTrue(empty($element), 'The lang tag has not been assigned to the English node.');
// Check if English node does not have dir tag.
$pattern = '|class="[^"]*node[^"]*"[^<>]*dir="ltr"|';
$this->assertNoPattern($pattern, 'The dir tag has not been assigned to the English node.');
$element = $this->cssSelect('article.node[dir="ltr"]');
$this->assertTrue(empty($element), 'The dir tag has not been assigned to the English node.');
// Check if Arabic node has lang="ar" & dir="rtl" tags.
$this->drupalGet('node/' . $nodes['ar']->id());
$pattern = '|class="[^"]*node[^"]*"[^<>]*lang="ar" dir="rtl"|';
$this->assertPattern($pattern, 'The lang and dir tags have been assigned correctly to the Arabic node.');
$element = $this->cssSelect('article.node[lang="ar"][dir="rtl"]');
$this->assertTrue(!empty($element), 'The lang and dir tags have been assigned correctly to the Arabic node.');
// Check if Spanish node has lang="es" tag.
$this->drupalGet('node/' . $nodes['es']->id());
$pattern = '|class="[^"]*node[^"]*"[^<>]*lang="es"|';
$this->assertPattern($pattern, 'The lang tag has been assigned correctly to the Spanish node.');
$element = $this->cssSelect('article.node[lang="es"]');
$this->assertTrue(!empty($element), 'The lang tag has been assigned correctly to the Spanish node.');
// Check if Spanish node does not have dir="ltr" tag.
$pattern = '|class="[^"]*node[^"]*"[^<>]*lang="es" dir="ltr"|';
$this->assertNoPattern($pattern, 'The dir tag has not been assigned to the Spanish node.');
$element = $this->cssSelect('article.node[lang="es"][dir="ltr"]');
$this->assertTrue(empty($element), 'The dir tag has not been assigned to the Spanish node.');
}
}
......@@ -650,25 +650,6 @@ function template_preprocess_node(&$variables) {
// Add article ARIA role.
$variables['attributes']['role'] = 'article';
// Gather node classes.
$variables['attributes']['class'][] = 'node';
$variables['attributes']['class'][] = drupal_html_class('node--type-' . $node->bundle());
if ($node->isPromoted()) {
$variables['attributes']['class'][] = 'node--promoted';
}
if ($node->isSticky()) {
$variables['attributes']['class'][] = 'node--sticky';
}
if (!$node->isPublished()) {
$variables['attributes']['class'][] = 'node--unpublished';
}
if ($variables['view_mode']) {
$variables['attributes']['class'][] = drupal_html_class('node--view-mode-' . $variables['view_mode']);
}
if (isset($node->preview)) {
$variables['attributes']['class'][] = 'node--preview';
}
}
/**
......
......@@ -11,14 +11,10 @@
* - createdtime: Formatted creation date. Preprocess functions can
* reformat it by calling format_date() with the desired parameters on
* $variables['node']->getCreatedTime().
* - promoted: Whether the node is promoted to the front page.
* - sticky: Whether the node is 'sticky'. Sticky nodes are ordered above
* other non-sticky nodes in teaser listings
* - published: Whether the node is published.
* - label: The title of the node.
* - content: All node items. Use {{ content }} to print them all,
* or print a subset such as {{ content.field_example }}. Use
* {{ content|without('field_example') %} to temporarily suppress the printing
* {{ content|without('field_example') }} to temporarily suppress the printing
* of a given child element.
* - author_picture: The node author user entity, rendered using the "compact"
* view mode.
......@@ -31,8 +27,8 @@
* The attributes.class element may contain one or more of the following
* classes:
* - node: The current template type (also known as a "theming hook").
* - node--[type]: The current node type. For example, if the node is a
* "Article" it would result in "node--article". Note that the machine
* - node--type-[type]: The current node type. For example, if the node is an
* "Article" it would result in "node--type-article". Note that the machine
* name will often be in a short form of the human readable label.
* - node--view-mode-[view_mode]: The View Mode of the node; for example, a
* teaser would result in: "node--view-mode-teaser", and
......@@ -74,7 +70,17 @@
* @ingroup themeable
*/
#}
<article{{ attributes }}>
{%
set classes = [
'node',
'node--type-' ~ node.bundle|clean_class,
node.isPromoted() ? 'node--promoted',
node.isSticky() ? 'node--sticky',
not node.isPublished() ? 'node--unpublished',
view_mode ? 'node--view-mode-' ~ view_mode|clean_class,
]
%}
<article{{ attributes.addClass(classes) }}>
{{ title_prefix }}
{% if not page %}
......@@ -87,14 +93,14 @@
{% if display_submitted %}
<footer class="node__meta">
{{ author_picture }}
<div class="node__submitted {{ author_attributes.class }}"{{ author_attributes|without('class') }}>
<div{{ author_attributes.addClass('node__submitted') }}>
{% trans %}Submitted by {{ author_name|passthrough }} on {{ date|passthrough }}{% endtrans %}
{{ metadata }}
</div>
</footer>
{% endif %}
<div class="node__content {{ content_attributes.class }}"{{ content_attributes|without('class') }}>
<div{{ content_attributes.addClass('node__content') }}>
{{ content|without('links') }}
</div>
......
......@@ -11,15 +11,11 @@
* - createdtime: Formatted creation date. Preprocess functions can
* reformat it by calling format_date() with the desired parameters on
* $variables['node']->getCreatedTime().
* - promoted: Whether the node is promoted to the front page.
* - sticky: Whether the node is 'sticky'. Sticky nodes are ordered above
* other non-sticky nodes in teaser listings
* - published: Whether the node is published.
* - label: The title of the node.
* - content: All node items. Use {{ content }} to print them all,
* or print a subset such as {{ content.field_example }}. Use
* {{ content|without('field_example') }} to exclude the printing of a
* given child element.
* {{ content|without('field_example') }} to temporarily suppress the printing
* of a given child element.
* - author_picture: The node author user entity, rendered using the "compact"
* view mode.
* - metadata: Metadata for this node.
......@@ -31,13 +27,12 @@
* The attributes.class element may contain one or more of the following
* classes:
* - node: The current template type (also known as a "theming hook").
* - node--[type]: The current node type. For example, if the node is a
* "Article" it would result in "node--article". Note that the machine
* - node--type-[type]: The current node type. For example, if the node is an
* "Article" it would result in "node--type-article". Note that the machine
* name will often be in a short form of the human readable label.
* - node--view-mode-[view_mode]: The View Mode of the node; for example, a
* teaser would result in: "node--view-mode-teaser",
* and full: "node--view-mode-full".
* - is-preview: Whether a node is in preview mode.
* teaser would result in: "node--view-mode-teaser", and
* full: "node--view-mode-full".
* The following are controlled through the node publishing options.
* - node--promoted: Appears on nodes promoted to the front page.
* - node--sticky: Appears on nodes ordered above other non-sticky nodes in
......@@ -69,12 +64,23 @@
* @see template_preprocess_node()
*/
#}
<article class="{{ attributes.class }} clearfix"{{ attributes|without('class') }}>
{%
set classes = [
'node',
'node--type-' ~ node.bundle|clean_class,
node.isPromoted() ? 'node--promoted',
node.isSticky() ? 'node--sticky',
not node.isPublished() ? 'node--unpublished',
view_mode ? 'node--view-mode-' ~ view_mode|clean_class,
'clearfix',
]
%}
<article{{ attributes.addClass(classes) }}>
<header>
{{ title_prefix }}
{% if not page %}
<h2 class="node__title {{ title_attributes.class }}"{{ title_attributes|without('class') }}>
<h2{{ title_attributes.addClass('node__title') }}>
<a href="{{ url }}" rel="bookmark">{{ label }}</a>
</h2>
{% endif %}
......@@ -91,7 +97,7 @@
{% endif %}
</header>
<div class="node__content clearfix {{ content_attributes.class }}"{{ content_attributes|without('class') }}>
<div{{ content_attributes.addClass('node__content', 'clearfix') }}>
{{ content|without('comment', 'links') }}
</div>
......
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