diff --git a/core/modules/node/node.module b/core/modules/node/node.module index aa26ce4..a326ba6 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -572,14 +572,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(), @@ -591,18 +586,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::service('renderer')->render($variables['elements']['created']); + $variables['author_name'] = \Drupal::service('renderer')->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 @@ -610,6 +601,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 5ed0775..8bef128 100644 --- a/core/modules/node/templates/node.html.twig +++ b/core/modules/node/templates/node.html.twig @@ -15,13 +15,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: @@ -42,14 +45,11 @@ * 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. diff --git a/core/modules/page_cache/src/Tests/PageCacheTagsIntegrationTest.php b/core/modules/page_cache/src/Tests/PageCacheTagsIntegrationTest.php index 95bd739..c956d3a 100644 --- a/core/modules/page_cache/src/Tests/PageCacheTagsIntegrationTest.php +++ b/core/modules/page_cache/src/Tests/PageCacheTagsIntegrationTest.php @@ -52,12 +52,14 @@ function testPageCacheTags() { )); $author_2 = $this->drupalCreateUser(); $node_2 = $this->drupalCreateNode(array( + 'type' => 'article', 'uid' => $author_2->id(), 'title' => 'Node 2', 'body' => array( 0 => array('value' => 'Body 2', 'format' => 'full_html'), ), 'promote' => NODE_PROMOTED, + 'display_submitted' => TRUE, )); // Place a block, but only make it visible on full node page 2. @@ -132,6 +134,7 @@ function testPageCacheTags() { 'node_view', 'node:' . $node_2->id(), 'user:' . $author_2->id(), + 'user_view', 'config:filter.format.full_html', 'config:system.menu.account', 'config:system.menu.tools', diff --git a/core/themes/bartik/bartik.theme b/core/themes/bartik/bartik.theme index 1f69448..f8004f5 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 25144bf..03b6621 100644 --- a/core/themes/bartik/templates/node.html.twig +++ b/core/themes/bartik/templates/node.html.twig @@ -15,13 +15,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: @@ -42,14 +45,11 @@ * 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. diff --git a/core/themes/classy/templates/content/node.html.twig b/core/themes/classy/templates/content/node.html.twig index 5d746a6..56fe671 100644 --- a/core/themes/classy/templates/content/node.html.twig +++ b/core/themes/classy/templates/content/node.html.twig @@ -15,13 +15,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: @@ -42,14 +45,11 @@ * 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.