diff --git a/core/modules/locale/src/Tests/LocaleContentTest.php b/core/modules/locale/src/Tests/LocaleContentTest.php index 3ec3c71..5229eb7 100644 --- a/core/modules/locale/src/Tests/LocaleContentTest.php +++ b/core/modules/locale/src/Tests/LocaleContentTest.php @@ -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->xpath('//article[@class and contains(concat(" ", normalize-space(@class), " "), " node ") and @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->xpath('//article[@class and contains(concat(" ", normalize-space(@class), " "), " node ") and @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->xpath('//article[@class and contains(concat(" ", normalize-space(@class), " "), " node ") and @lang="ar" and @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->xpath('//article[@class and contains(concat(" ", normalize-space(@class), " "), " node ") and @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->xpath('//article[@class and contains(concat(" ", normalize-space(@class), " "), " node ") and @lang="es" and @dir="ltr"]'); + $this->assertTrue(empty($element), 'The dir tag has not been assigned to the Spanish node.'); } } diff --git a/core/modules/node/node.module b/core/modules/node/node.module index d96052d..751663a 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -651,25 +651,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'; - } } /** diff --git a/core/modules/node/templates/node.html.twig b/core/modules/node/templates/node.html.twig index a08b064..e29b93e 100644 --- a/core/modules/node/templates/node.html.twig +++ b/core/modules/node/templates/node.html.twig @@ -11,10 +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 + * - isPromoted: Whether the node is promoted to the front page. + * - isSticky: Whether the node is 'sticky'. Sticky nodes are ordered above * other non-sticky nodes in teaser listings - * - published: Whether the node is published. + * - isPublished: 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 @@ -76,7 +76,18 @@ * @ingroup themeable */ #} - +{% + set classes = [ + 'node', + 'node--type-' ~ node.bundle|clean_class, + node.isPromoted ? 'node--promoted', + node.isSticky ? 'node--sticky', + not node.isPublished ? 'node--unpublished', + 'node--view-mode-' ~ view_mode|clean_class, + preview ? 'node--preview', + ] +%} + {{ title_prefix }} {% if not page %} @@ -89,15 +100,15 @@ {% if display_submitted %}
{{ author_picture }} -
{% endif %} -
- {{ content|without('links') }} + + {{ content|without('links') }}
{% if content.links %} diff --git a/core/themes/bartik/templates/node.html.twig b/core/themes/bartik/templates/node.html.twig index d45b0f0..9e95734 100644 --- a/core/themes/bartik/templates/node.html.twig +++ b/core/themes/bartik/templates/node.html.twig @@ -11,10 +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 + * - isPromoted: Whether the node is promoted to the front page. + * - isSticky: Whether the node is 'sticky'. Sticky nodes are ordered above * other non-sticky nodes in teaser listings - * - published: Whether the node is published. + * - isPublished: 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 @@ -71,12 +71,24 @@ * @see template_preprocess_node() */ #} -
+{% + set classes = [ + 'node', + 'node--type-' ~ node.bundle|clean_class, + node.isPromoted ? 'node--promoted', + node.isSticky ? 'node--sticky', + not node.isPublished ? 'node--unpublished', + 'node--view-mode-' ~ view_mode|clean_class, + preview ? 'node--preview', + 'clearfix', + ] +%} +
{{ title_prefix }} {% if not page %} -

+ {{ label }}

{% endif %} @@ -93,7 +105,7 @@ {% endif %}
-
+ {{ content|without('comment', 'links') }}