diff --git a/core/modules/node/content_types.inc b/core/modules/node/content_types.inc index e838460..8aea2b7 100644 --- a/core/modules/node/content_types.inc +++ b/core/modules/node/content_types.inc @@ -75,7 +75,8 @@ function node_overview_types() { } /** - * Returns HTML for a node type description for the content type admin page. + * Preprocess variables for node-admin-overview.html.twig, a node type + * description for the content type admin page. * * @param $variables * An associative array containing: @@ -88,14 +89,10 @@ function node_overview_types() { * * @ingroup themeable */ -function theme_node_admin_overview($variables) { - $name = $variables['name']; - $type = $variables['type']; - - $output = check_plain($name); - $output .= ' ' . t('(Machine name: @type)', array('@type' => $type->type)) . ''; - $output .= '
' . filter_xss_admin($type->description) . '
'; - return $output; +function template_preprocess_node_admin_overview(&$variables) { + $variables['name'] = check_plain($variables['name']); + $variables['description'] = filter_xss_admin($variables['type']->description); + $variables['machine_name'] = $variables['type']->type; } /** diff --git a/core/modules/node/node.api.php b/core/modules/node/node.api.php index 1207238..df0d3bc 100644 --- a/core/modules/node/node.api.php +++ b/core/modules/node/node.api.php @@ -698,7 +698,7 @@ function hook_node_prepare(Drupal\node\Node $node) { * theming. * * @see template_preprocess_search_result() - * @see search-result.tpl.php + * @see search-result.html.twig * * @ingroup node_api_hooks */ @@ -890,8 +890,8 @@ function hook_node_view(\Drupal\node\Plugin\Core\Entity\Node $node, \Drupal\enti * If the module wishes to act on the rendered HTML of the node rather than the * structured content array, it may use this hook to add a #post_render * callback. Alternatively, it could also implement hook_preprocess_HOOK() for - * node.tpl.php. See drupal_render() and theme() documentation respectively for - * details. + * node.html.twig. See drupal_render() and theme() documentation respectively + * for details. * * @param $build * A renderable array representing the node content. diff --git a/core/modules/node/node.module b/core/modules/node/node.module index ad79f6d..0e0fd31 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -153,23 +153,30 @@ function node_theme() { ), 'node_search_admin' => array( 'render element' => 'form', + 'template' => 'node-search-admin', ), 'node_add_list' => array( 'variables' => array('content' => NULL), 'file' => 'node.pages.inc', + 'template' => 'node-add-list', ), 'node_preview' => array( 'variables' => array('node' => NULL), 'file' => 'node.pages.inc', + 'template' => 'node-preview', ), 'node_admin_overview' => array( 'variables' => array('name' => NULL, 'type' => NULL), + 'file' => 'content_types.inc', + 'template' => 'node-admin-overview', ), 'node_recent_block' => array( 'variables' => array('nodes' => NULL), + 'template' => 'node-recent-block', ), 'node_recent_content' => array( 'variables' => array('node' => NULL), + 'template' => 'node-recent-content', ), 'node_edit_form' => array( 'render element' => 'form', @@ -1107,7 +1114,7 @@ function node_is_page(Node $node) { } /** - * Implements hook_preprocess_HOOK() for block.tpl.php. + * Implements hook_preprocess_HOOK() for block.html.twig. */ function node_preprocess_block(&$variables) { if ($variables['block']->module == 'node') { @@ -1123,11 +1130,11 @@ function node_preprocess_block(&$variables) { } /** - * Processes variables for node.tpl.php. + * Preprocess variables for node.html.twig. * - * Most themes utilize their own copy of node.tpl.php. The default is located - * inside "modules/node/node.tpl.php". Look in there for the full list of - * variables. + * Most themes utilize their own copy of node.html.twig. The default is located + * inside "core/modules/node/templates/node.html.twig". Look in there for the + * full list of variables. * * @param $variables * An associative array containing: @@ -1135,7 +1142,7 @@ function node_preprocess_block(&$variables) { * - node: The node object. * - view_mode: View mode; e.g., 'full', 'teaser'... * - * @see node.tpl.php + * @see node.html.twig */ function template_preprocess_node(&$variables) { $variables['view_mode'] = $variables['elements']['#view_mode']; @@ -1157,7 +1164,7 @@ function template_preprocess_node(&$variables) { // Make useful flags and node data available. // @todo: The comment properties only exist if comment.module is enabled, but - // are documented in node.tpl.php, so we make sure that they are set. + // are documented in node.html.twig, so we make sure that they are set. // Consider removing them. $properties = array('type', 'comment_count', 'uid', 'created', 'promote', 'sticky', 'status', 'comment'); foreach ($properties as $property) { @@ -1509,7 +1516,8 @@ function node_user_predelete($account) { } /** - * Returns HTML for the content ranking part of the search settings admin page. + * Preprocess variables for node-search-admin.html.twig, the content ranking + * part of the search settings admin page. * * @param $variables * An associative array containing: @@ -1518,7 +1526,7 @@ function node_user_predelete($account) { * @see node_search_admin() * @ingroup themeable */ -function theme_node_search_admin($variables) { +function template_preprocess_node_search_admin(&$variables) { $form = $variables['form']; $output = drupal_render($form['info']); @@ -1531,10 +1539,13 @@ function theme_node_search_admin($variables) { $row[] = drupal_render($form['factors'][$key]); $rows[] = $row; } - $output .= theme('table', array('header' => $header, 'rows' => $rows)); - $output .= drupal_render_children($form); - return $output; + $variables['table'] = array( + '#theme' => 'table', + '#header' => $header, + '#rows' => $rows, + ); + $variables['form'] = drupal_render_children($form); } /** @@ -1933,7 +1944,8 @@ function node_get_recent($number = 10) { } /** - * Returns HTML for a list of recent content. + * Preprocess variables for node-recent-content.html.twig, a list of recently + * created content. * * @param $variables * An associative array containing: @@ -1941,9 +1953,8 @@ function node_get_recent($number = 10) { * * @ingroup themeable */ -function theme_node_recent_block($variables) { +function template_preprocess_node_recent_block(&$variables) { $rows = array(); - $output = ''; $l_options = array('query' => drupal_get_destination()); foreach ($variables['nodes'] as $node) { @@ -1967,18 +1978,26 @@ function theme_node_recent_block($variables) { $rows[] = $row; } + $variables['table'] = array(); + $variables['more_link'] = array(); if ($rows) { - $output = theme('table', array('rows' => $rows)); + $variables['table'] = array( + '#theme' => 'table', + '#rows' => $rows, + ); if (user_access('access content overview')) { - $output .= theme('more_link', array('url' => 'admin/content', 'title' => t('Show more content'))); + $variables['more_link'] = array( + '#theme' => 'more_link', + '#url' => 'admin/content', + '#title' => t('Show more content'), + ); } } - - return $output; } /** - * Returns HTML for a recent node to be displayed in the recent content block. + * Preprocess variables for node-recent-content.twig, a recent node to be + * displayed in the recent content block. * * @param $variables * An associative array containing: @@ -1986,17 +2005,17 @@ function theme_node_recent_block($variables) { * * @ingroup themeable */ -function theme_node_recent_content($variables) { +function template_preprocess_node_recent_content(&$variables) { $node = $variables['node']; - - $output = '
'; - $output .= l($node->label(), 'node/' . $node->nid); - $output .= theme('mark', array('type' => node_mark($node->nid, $node->changed))); - $output .= '
'; - $output .= theme('username', array('account' => user_load($node->uid))); - $output .= '
'; - - return $output; + $variables['link'] = l($node->label(), 'node/' . $node->nid); + $variables['mark'] = array( + '#theme' => 'mark', + '#type' => node_mark($node->nid, $node->changed), + ); + $variables['username'] = array( + '#theme' => 'username', + '#account' => user_load($node->uid), + ); } /** diff --git a/core/modules/node/node.pages.inc b/core/modules/node/node.pages.inc index 008ef76..fa2fc16 100644 --- a/core/modules/node/node.pages.inc +++ b/core/modules/node/node.pages.inc @@ -56,7 +56,8 @@ function node_add_page() { } /** - * Returns HTML for a list of available node types for node creation. + * Preprocess variables for node-add-list.html.twig, a list of available node + * types for node creation. * * @param $variables * An associative array containing: @@ -66,22 +67,14 @@ function node_add_page() { * * @ingroup themeable */ -function theme_node_add_list($variables) { - $content = $variables['content']; - $output = ''; - - if ($content) { - $output = '
'; - foreach ($content as $type) { - $output .= '
' . l($type->name, 'node/add/' . $type->type) . '
'; - $output .= '
' . filter_xss_admin($type->description) . '
'; +function template_preprocess_node_add_list(&$variables) { + if (!empty($variables['content'])) { + foreach ($variables['content'] as $type) { + $variables['types'][$type->type]['type'] = $type->type; + $variables['types'][$type->type]['add_link'] = l($type->name, 'node/add/' . $type->type); + $variables['types'][$type->type]['description'] = filter_xss_admin($type->description); } - $output .= '
'; } - else { - $output = '

' . t('You have not created any content types yet. Go to the content type creation page to add a new content type.', array('@create-content' => url('admin/structure/types/add'))) . '

'; - } - return $output; } @@ -157,7 +150,8 @@ function node_preview(Node $node) { } /** - * Returns HTML for a node preview for display during node creation and editing. + * Preprocess variables for node-preview.html.twig, a node preview for display + * during node creation and editing. * * @param $variables * An associative array containing: @@ -168,30 +162,26 @@ function node_preview(Node $node) { * * @ingroup themeable */ -function theme_node_preview($variables) { +function template_preprocess_node_preview(&$variables) { $node = $variables['node']; - $output = ''; - - $elements = node_view($node, 'teaser'); - $elements['#attached']['library'][] = array('node', 'drupal.node.preview'); - $trimmed = drupal_render($elements); - $elements = node_view($node, 'full'); - $full = drupal_render($elements); - - // Do we need to preview trimmed version of post as well as full version? - if ($trimmed != $full) { + // Render trimmed teaser version of the post. + $node_teaser = node_view(clone $node, 'teaser'); + $node_teaser['#attached']['library'][] = array('node', 'drupal.node.preview'); + $variables['teaser'] = $node_teaser; + // Render full version of the post. + $node_full = node_view($node, 'full'); + $variables['full'] = $node_full; + + // Do we need to preview a trimmed teaser version of a post as well as a full + // version? + if ($variables['teaser'] != $variables['full']) { drupal_set_message(t('The trimmed version of your post shows what your post looks like when promoted to the main page or when exported for syndication. You can insert the delimiter "<!--break-->" (without the quotes) to fine-tune where your post gets split.')); - $output .= '

' . t('Preview trimmed version') . '

'; - $output .= $trimmed; - $output .= '

' . t('Preview full version') . '

'; - $output .= $full; + $variables['preview_teaser'] = TRUE; } else { - $output .= $full; + $variables['preview_teaser'] = FALSE; } - - return $output; } /** diff --git a/core/modules/node/templates/node-add-list.html.twig b/core/modules/node/templates/node-add-list.html.twig new file mode 100644 index 0000000..0f629ad --- /dev/null +++ b/core/modules/node/templates/node-add-list.html.twig @@ -0,0 +1,25 @@ +{# +/** + * @file + * Default theme implementation to list the available types for content creation. + * + * Available variables: + * - types: List of content types. + * - no_content_text: Text displayed when no content types are available. + * + * @see template_preprocess() + * @see template_preprocess_node_add_list() + * + * @ingroup themeable + */ +#} +{% if content %} +
+ {% for type in types %} +
{{ type.add_link }}
+
{{ type.description }}
+ {% endfor %} +
+{% else %} +

{{ 'You have not created any content types yet. Go to the content type creation page to add a new content type.'|t({'@create-content': url('admin/structure/types/add')}) }}

+{% endif %} diff --git a/core/modules/node/templates/node-admin-overview.html.twig b/core/modules/node/templates/node-admin-overview.html.twig new file mode 100644 index 0000000..7ea022b --- /dev/null +++ b/core/modules/node/templates/node-admin-overview.html.twig @@ -0,0 +1,19 @@ +{# +/** + * @file + * Default theme implementation for a node type description for the + * content type admin page. + * + * Available variables: + * - name: Human readable name of the content type. + * - machine_name: Machine readable name of the content type. + * - description: Description of the content type. + * + * @see template_preprocess() + * @see template_preprocess_node_admin_overview() + * + * @ingroup themeable + */ +#} +{{ name }} {{ '(Machine name: @type)'|t({'@type': machine_name}) }} +
{{ description }}
diff --git a/core/modules/node/templates/node-preview.html.twig b/core/modules/node/templates/node-preview.html.twig new file mode 100644 index 0000000..1611c7e --- /dev/null +++ b/core/modules/node/templates/node-preview.html.twig @@ -0,0 +1,25 @@ +{# +/** + * @file + * Default theme implementation for a node preview. + * + * This display may be used during node creation and editing. + * + * Available variables: + * - preview_teaser: Flag indicating whether or not to show a trimmed teaser + * version. + * - teaser: Trimmed teaser version of the node. + * - full: Full version of the node. + * + * @see template_preprocess() + * @see template_preprocess_node_preview() + * + * @ingroup themeable + */ +#} +{% if preview_teaser %} +

{{ "Preview trimmed version"|t }}

+ {{ teaser }} +

{{ "Preview full version"|t }}

+{% endif %} +{{ full }} diff --git a/core/modules/node/templates/node-recent-block.html.twig b/core/modules/node/templates/node-recent-block.html.twig new file mode 100644 index 0000000..b8cfd81 --- /dev/null +++ b/core/modules/node/templates/node-recent-block.html.twig @@ -0,0 +1,21 @@ +{# +/** + * @file + * Default theme implementation for a list of recent content. + * + * Available variables: + * - table: A rendered HTML table of recent content. + * - more_link: A rendered link to show more content. + * + * @see template_preprocess() + * @see template_preprocess_node_recent_block() + * + * @ingroup themeable + */ +#} +{% if table %} + {{ table }} +{% endif %} +{% if more_link %} + {{ more_link }} +{% endif %} diff --git a/core/modules/node/templates/node-recent-content.html.twig b/core/modules/node/templates/node-recent-content.html.twig new file mode 100644 index 0000000..ef52547 --- /dev/null +++ b/core/modules/node/templates/node-recent-content.html.twig @@ -0,0 +1,18 @@ +{# +/** + * @file + * Default theme implementation for a recent node to be displayed in the recent content block. + * + * Available variables: + * - link: Link to the content. + * - mark: HTML marker for new or updated content. + * - username: The author of the content. + * + * @see template_preprocess() + * @see template_preprocess_node_recent_content() + * + * @ingroup themeable + */ +#} +
{{ link }}{{ mark }}
+
{{ username }}
diff --git a/core/modules/node/templates/node-search-admin.html.twig b/core/modules/node/templates/node-search-admin.html.twig new file mode 100644 index 0000000..4e4e1fb --- /dev/null +++ b/core/modules/node/templates/node-search-admin.html.twig @@ -0,0 +1,17 @@ +{# +/** + * @file + * Returns HTML for the content ranking part of the search settings admin page. + * + * Available variables: + * - table: The table of the settings. + * - form: A render element representing the form. + * + * @see template_preprocess() + * @see template_preprocess_node_search_admin() + * + * @ingroup themeable + */ +#} +{{ table }} +{{ form }} diff --git a/core/modules/node/templates/node.html.twig b/core/modules/node/templates/node.html.twig index f1e0b5a..9a574f2 100644 --- a/core/modules/node/templates/node.html.twig +++ b/core/modules/node/templates/node.html.twig @@ -4,22 +4,21 @@ * Default theme implementation to display a node. * * Available variables: - * - label: the title of the node. - * - content: node items. Use {{ content }} to print them all, + * - title: The node title. + * - content: An array of node items. Use {{ content }} to print them all, * or print a subset such as {{ content.field_example }}. Use * {% hide(content.field_example) %} to temporarily suppress the printing * of a given element. + * - author: Themed username of node author output from theme_username(). * - user_picture: The node author's picture from user-picture.html.twig. - * - date: Formatted creation date. Preprocess functions can reformat it by - * calling format_date() with the desired parameters on - * $variables['created']. - * - name: Themed username of node author output from theme_username(). + * - created: Formatted creation date. Preprocess functions can reformat it by + * calling format_date() with the desired parameters on the $created variable. + * - changed: Formatted last updated date. * - node_url: Direct URL of the current node. * - display_submitted: Whether submission information should be displayed. - * - submitted: Submission information created from name and date during - * template_preprocess_node(). - * - attributes: HTML attributes for the surrounding element. - * Attributes include the 'class' information, which contains: + * - attributes: An instance of the Attributes class that can be manipulated as + * an array and printed as a string. + * It includes the 'class' information, which contains: * - node: The current template type; for example, "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 @@ -38,11 +37,10 @@ * displayed after the main title tag that appears in the template. * * Other variables: - * - node: Fully loaded node entity. + * - node: Full node entity. Contains data that may not be safe. * - type: Node type; for example, page, article, etc. * - comment_count: Number of comments attached to the node. * - uid: User ID of the node author. - * - created: Time the node was published formatted as a Unix timestamp. * - zebra: Outputs either "even" or "odd". Useful for zebra striping in * teaser listings. * - id: Position of the node. Increments each time it's output. @@ -73,16 +71,18 @@ * @see template_preprocess() * @see template_preprocess_node() * + * @todo Might be a good idea to remove the id attribute, because if that gets + * rendered twice on a page this is invalid CSS for example: two lists + * in different view modes. + * * @ingroup themeable */ #} -
+
{{ title_prefix }} {% if not page %} - - {{ label }} - +

{{ label }}

{% endif %} {{ title_suffix }} @@ -93,7 +93,7 @@ {% endif %} -
+
{# We hide the comments and links now so that we can render them later. #} {% hide(content.comments) %} {% hide(content.links) %} diff --git a/core/modules/node/templates/node.tpl.php b/core/modules/node/templates/node.tpl.php deleted file mode 100644 index 196d26f..0000000 --- a/core/modules/node/templates/node.tpl.php +++ /dev/null @@ -1,106 +0,0 @@ -body becomes $body. When needing to - * access a field's raw values, developers/themers are strongly encouraged to - * use these variables. Otherwise they will have to explicitly specify the - * desired field language; for example, $node->body['en'], thus overriding any - * language negotiation rule that was previously applied. - * - * @see template_preprocess() - * @see template_preprocess_node() - * @see template_process() - * - * @ingroup themeable - */ -?> -
> - - - - > - - - - -
- - -
- - -
> - -
- - - - -