diff --git a/core/modules/node/node.module b/core/modules/node/node.module index 124a060..d4e24a9 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -546,14 +546,9 @@ function node_theme_suggestions_node(array $variables) { function template_preprocess_node(&$variables) { $variables['view_mode'] = $variables['elements']['#view_mode']; // Provide a distinct $teaser boolean. - $variables['teaser'] = $variables['view_mode'] == 'teaser'; $variables['node'] = $variables['elements']['#node']; /** @var \Drupal\node\NodeInterface $node */ $node = $variables['node']; - $variables['date'] = drupal_render($variables['elements']['created']); - unset($variables['elements']['created']); - $variables['author_name'] = drupal_render($variables['elements']['uid']); - unset($variables['elements']['uid']); $variables['url'] = $node->url('canonical', array( 'language' => $node->language(), @@ -565,18 +560,14 @@ function template_preprocess_node(&$variables) { // - The node is in preview and view mode is either 'full' or 'default'. $variables['page'] = ($variables['view_mode'] == 'full' && (node_is_page($node)) || (isset($node->in_preview) && in_array($node->preview_view_mode, array('full', 'default')))); - // Helpful $content variable for templates. - $variables += array('content' => array()); - foreach (Element::children($variables['elements']) as $key) { - $variables['content'][$key] = $variables['elements'][$key]; - } - // Display post information only on certain node types. $node_type = $node->type->entity; // Used by RDF to add attributes around the author and date submitted. - $variables['author_attributes'] = new Attribute(); $variables['display_submitted'] = $node_type->displaySubmitted(); if ($variables['display_submitted']) { + $variables['author_attributes'] = new Attribute(); + $variables['date'] = drupal_render($variables['elements']['created']); + $variables['author_name'] = drupal_render($variables['elements']['uid']); if (theme_get_setting('features.node_user_picture')) { // To change user picture settings (e.g. image style), edit the 'compact' // view mode on the User entity. Note that the 'compact' view mode might @@ -584,6 +575,14 @@ function template_preprocess_node(&$variables) { $variables['author_picture'] = user_view($node->getOwner(), 'compact'); } } + unset($variables['elements']['uid']); + unset($variables['elements']['created']); + + // Helpful $content variable for templates. + $variables += array('content' => array()); + foreach (Element::children($variables['elements']) as $key) { + $variables['content'][$key] = $variables['elements'][$key]; + } // Add article ARIA role. $variables['attributes']['role'] = 'article'; diff --git a/core/modules/node/templates/node.html.twig b/core/modules/node/templates/node.html.twig index a78fcb3..70c4869 100644 --- a/core/modules/node/templates/node.html.twig +++ b/core/modules/node/templates/node.html.twig @@ -16,13 +16,16 @@ * or print a subset such as {{ content.field_example }}. Use * {{ 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. - * - date: Themed creation date field. - * - author_name: Themed author name field. * - url: Direct URL of the current node. * - display_submitted: Whether submission information should be displayed. + * If display_submitted is set, additional variables are prepared: + * - author_picture: The node author user entity, rendered using the "compact" + * view mode. + * - date: Themed creation date field. + * - author_name: Themed author name field. + * - author_attributes: Same as attributes, except applied to the author of + * the node that appears in the template. * - attributes: HTML attributes for the containing element. * The attributes.class element may contain one or more of the following * classes: @@ -43,17 +46,15 @@ * tag that appears in the template. * - content_attributes: Same as attributes, except applied to the main * content tag that appears in the template. - * - author_attributes: Same as attributes, except applied to the author of - * the node tag that appears in the template. * - title_prefix: Additional output populated by modules, intended to be * displayed in front of the main title tag that appears in the template. * - title_suffix: Additional output populated by modules, intended to be * displayed after the main title tag that appears in the template. * - view_mode: View mode; for example, "teaser" or "full". - * - teaser: Flag for the teaser state. Will be true if view_mode is 'teaser'. * - page: Flag for the full page state. Will be true if view_mode is 'full'. * - readmore: Flag for more state. Will be true if the teaser content of the * node cannot hold the main body content. + * - is_front: Flag for front. Will be true when presented on the front page. * - logged_in: Flag for authenticated user status. Will be true when the * current user is a logged-in member. * - is_admin: Flag for admin user status. Will be true when the current user diff --git a/core/modules/system/src/Tests/Cache/PageCacheTagsIntegrationTest.php b/core/modules/system/src/Tests/Cache/PageCacheTagsIntegrationTest.php index 3fc3e34..7ffda02 100644 --- a/core/modules/system/src/Tests/Cache/PageCacheTagsIntegrationTest.php +++ b/core/modules/system/src/Tests/Cache/PageCacheTagsIntegrationTest.php @@ -49,6 +49,7 @@ function testPageCacheTags() { )); $author_2 = $this->drupalCreateUser(); $node_2 = $this->drupalCreateNode(array( + 'type' => 'article', 'uid' => $author_2->id(), 'title' => 'Node 2', 'body' => array( @@ -124,6 +125,8 @@ function testPageCacheTags() { 'config:system.menu.tools', 'config:system.menu.footer', 'config:system.menu.main', + 'user_view', + 'comment_list', )); } diff --git a/core/themes/bartik/bartik.theme b/core/themes/bartik/bartik.theme index 145c15c..9f338af 100644 --- a/core/themes/bartik/bartik.theme +++ b/core/themes/bartik/bartik.theme @@ -87,7 +87,7 @@ function bartik_preprocess_maintenance_page(&$variables) { function bartik_preprocess_node(&$variables) { // Remove the "Add new comment" link on teasers or when the comment form is // displayed on the page. - if ($variables['teaser'] || !empty($variables['content']['comments']['comment_form'])) { + if ($variables['view_mode'] == 'teaser' || !empty($variables['content']['comments']['comment_form'])) { unset($variables['content']['links']['comment']['#links']['comment-add']); } } diff --git a/core/themes/bartik/templates/node.html.twig b/core/themes/bartik/templates/node.html.twig index b390681..2505649 100644 --- a/core/themes/bartik/templates/node.html.twig +++ b/core/themes/bartik/templates/node.html.twig @@ -1,7 +1,7 @@ {# /** * @file - * Bartik's theme implementation to display a node. + * Default theme implementation to display a node. * * Available variables: * - node: Full node entity. @@ -16,13 +16,16 @@ * or print a subset such as {{ content.field_example }}. Use * {{ 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. - * - date: Themed creation date field. - * - author_name: Themed author name field. * - url: Direct URL of the current node. * - display_submitted: Whether submission information should be displayed. + * If display_submitted is set, additional variables are prepared: + * - author_picture: The node author user entity, rendered using the "compact" + * view mode. + * - date: Themed creation date field. + * - author_name: Themed author name field. + * - author_attributes: Same as attributes, except applied to the author of + * the node that appears in the template. * - attributes: HTML attributes for the containing element. * The attributes.class element may contain one or more of the following * classes: @@ -43,17 +46,15 @@ * tag that appears in the template. * - content_attributes: Same as attributes, except applied to the main * content tag that appears in the template. - * - author_attributes: Same as attributes, except applied to the author of - * the node tag that appears in the template. * - title_prefix: Additional output populated by modules, intended to be * displayed in front of the main title tag that appears in the template. * - title_suffix: Additional output populated by modules, intended to be * displayed after the main title tag that appears in the template. * - view_mode: View mode; for example, "teaser" or "full". - * - teaser: Flag for the teaser state. Will be true if view_mode is 'teaser'. * - page: Flag for the full page state. Will be true if view_mode is 'full'. * - readmore: Flag for more state. Will be true if the teaser content of the * node cannot hold the main body content. + * - is_front: Flag for front. Will be true when presented on the front page. * - logged_in: Flag for authenticated user status. Will be true when the * current user is a logged-in member. * - is_admin: Flag for admin user status. Will be true when the current user