summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2013-05-24 17:13:55 (GMT)
committerAlex Pott2013-05-24 17:13:55 (GMT)
commit6b4b127e2e6d5db62b8d4abda4d127e514c80a3e (patch)
tree121363e3f2df355380d90e68d332bfc48f18d276
parent5f9bee77071027a4fee1544a5e66773a30f7a74b (diff)
Issue #1898432 by WebDevDude, steveoliver, vlad.dancer, jenlampton, pixelmord, Fabianx, iztok, EVIIILJ, jwilson3, c4rl, Cottser: Convert node module to Twig.
-rw-r--r--core/includes/common.inc4
-rw-r--r--core/includes/entity.api.php2
-rw-r--r--core/modules/edit/edit.module2
-rw-r--r--core/modules/locale/locale.module2
-rw-r--r--core/modules/node/node.api.php4
-rw-r--r--core/modules/node/node.module36
-rw-r--r--core/modules/node/templates/node-edit-form.html.twig30
-rw-r--r--core/modules/node/templates/node-edit-form.tpl.php27
-rw-r--r--core/modules/node/templates/node.html.twig67
-rw-r--r--core/modules/node/templates/node.tpl.php103
-rw-r--r--core/modules/rdf/rdf.module10
11 files changed, 95 insertions, 192 deletions
diff --git a/core/includes/common.inc b/core/includes/common.inc
index 2b3b632..8b9d9e3 100644
--- a/core/includes/common.inc
+++ b/core/includes/common.inc
@@ -4994,14 +4994,14 @@ function drupal_pre_render_link($element) {
*
* In this example, the links are grouped by functionality, which can be
* helpful to themers who want to display certain kinds of links independently.
- * For example, adding this code to node.tpl.php will result in the comment
+ * For example, adding this code to node.html.twig will result in the comment
* links being rendered as a single list:
* @code
* print render($content['links']['comment']);
* @endcode
*
* (where $node->content has been transformed into $content before handing
- * control to the node.tpl.php template).
+ * control to the node.html.twig template).
*
* The pre_render function defined here allows the above flexibility, but also
* allows the following code to be used to render all remaining links into a
diff --git a/core/includes/entity.api.php b/core/includes/entity.api.php
index 148f11d..1912fe1 100644
--- a/core/includes/entity.api.php
+++ b/core/includes/entity.api.php
@@ -344,7 +344,7 @@ function hook_entity_view(\Drupal\Core\Entity\EntityInterface $entity, \Drupal\e
* If a module wishes to act on the rendered HTML of the entity 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
- * the particular entity type template, if there is one (e.g., node.tpl.php).
+ * the particular entity type template, if there is one (e.g., node.html.twig).
* See drupal_render() and theme() for details.
*
* @param $build
diff --git a/core/modules/edit/edit.module b/core/modules/edit/edit.module
index 6a73d89..7e1d1fe 100644
--- a/core/modules/edit/edit.module
+++ b/core/modules/edit/edit.module
@@ -137,7 +137,7 @@ function edit_preprocess_field(&$variables) {
}
/**
- * Implements hook_preprocess_HOOK() for node.tpl.php.
+ * Implements hook_preprocess_HOOK() for node.html.twig.
*
* @todo Remove this, handle in generic way: http://drupal.org/node/1972514.
*/
diff --git a/core/modules/locale/locale.module b/core/modules/locale/locale.module
index 75e0a22..31fd0fc 100644
--- a/core/modules/locale/locale.module
+++ b/core/modules/locale/locale.module
@@ -870,7 +870,7 @@ function locale_system_file_system_settings_submit(&$form, $form_state) {
}
/**
- * Implements hook_preprocess_HOOK() for node.tpl.php.
+ * Implements hook_preprocess_HOOK() for node.html.twig.
*/
function locale_preprocess_node(&$variables) {
if ($variables['node']->langcode != LANGUAGE_NOT_SPECIFIED) {
diff --git a/core/modules/node/node.api.php b/core/modules/node/node.api.php
index 78a3139..b6cd024 100644
--- a/core/modules/node/node.api.php
+++ b/core/modules/node/node.api.php
@@ -898,8 +898,8 @@ function hook_node_view(\Drupal\Core\Entity\EntityInterface $node, \Drupal\entit
* 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 5c934df..23bf4be 100644
--- a/core/modules/node/node.module
+++ b/core/modules/node/node.module
@@ -174,7 +174,6 @@ function node_theme() {
),
'node_edit_form' => array(
'render element' => 'form',
- 'path' => drupal_get_path('module', 'node') . '/templates',
'template' => 'node-edit-form',
),
);
@@ -1091,19 +1090,19 @@ function node_preprocess_block(&$variables) {
}
/**
- * Processes variables for node.tpl.php.
+ * Prepares variables for node templates.
*
- * 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.
+ * Default template: node.html.twig.
*
- * @param $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 array $variables
* An associative array containing:
* - elements: An array of elements to display in view mode.
* - node: The node object.
* - view_mode: View mode; e.g., 'full', 'teaser'...
- *
- * @see node.tpl.php
*/
function template_preprocess_node(&$variables) {
$variables['view_mode'] = $variables['elements']['#view_mode'];
@@ -1112,25 +1111,18 @@ function template_preprocess_node(&$variables) {
$variables['node'] = $variables['elements']['#node'];
$node = $variables['node'];
- $variables['date'] = format_date($node->created);
- $variables['name'] = theme('username', array(
+ $variables['date'] = format_date($node->created);
+ // @todo Change 'name' to 'author' and also convert to a render array pending
+ // http://drupal.org/node/1941286.
+ $variables['name'] = theme('username', array(
'account' => $node,
'link_attributes' => array('rel' => 'author'),
));
$uri = $node->uri();
$variables['node_url'] = url($uri['path'], $uri['options']);
- $variables['label'] = check_plain($node->label());
- $variables['page'] = $variables['view_mode'] == 'full' && node_is_page($node);
-
- // 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.
- // Consider removing them.
- $properties = array('type', 'comment_count', 'uid', 'created', 'promote', 'sticky', 'status', 'comment');
- foreach ($properties as $property) {
- $variables[$property] = isset($node->$property) ? $node->$property : NULL;
- }
+ $variables['label'] = check_plain($node->label());
+ $variables['page'] = $variables['view_mode'] == 'full' && node_is_page($node);
// Helpful $content variable for templates.
$variables += array('content' => array());
@@ -1186,6 +1178,8 @@ function template_preprocess_node(&$variables) {
// Clean up name so there are no underscores.
$variables['theme_hook_suggestions'][] = 'node__' . $node->type;
$variables['theme_hook_suggestions'][] = 'node__' . $node->nid;
+
+ $variables['content_attributes']['class'][] = 'content';
}
/**
diff --git a/core/modules/node/templates/node-edit-form.html.twig b/core/modules/node/templates/node-edit-form.html.twig
new file mode 100644
index 0000000..eee9ecc
--- /dev/null
+++ b/core/modules/node/templates/node-edit-form.html.twig
@@ -0,0 +1,30 @@
+{#
+/**
+ * @file
+ * Two column template for the node add/edit form.
+ *
+ * This template will be used when a node edit form specifies 'node_edit_form'
+ * as its #theme callback. Otherwise, by default, node add/edit forms will be
+ * themed by theme_form().
+ *
+ * Available variables:
+ * - form: The node add/edit form.
+ *
+ * @see seven_form_node_form_alter()
+ *
+ * @ingroup themeable
+ */
+#}
+{% hide(form.advanced) %}
+{% hide(form.actions) %}
+<div class="layout-node-form clearfix">
+ <div class="layout-region layout-region-node-main">
+ {{ form }}
+ </div>
+ <div class="layout-region layout-region-node-secondary">
+ {{ form.advanced }}
+ </div>
+ <div class="layout-region layout-region-node-footer">
+ {{ form.actions }}
+ </div>
+</div>
diff --git a/core/modules/node/templates/node-edit-form.tpl.php b/core/modules/node/templates/node-edit-form.tpl.php
deleted file mode 100644
index 7b76683..0000000
--- a/core/modules/node/templates/node-edit-form.tpl.php
+++ /dev/null
@@ -1,27 +0,0 @@
-<?php
-
-/**
- * @file
- * Two column template for the node add/edit form.
- *
- * Available variables:
- * - $form: The actual form to print.
- */
-
-hide($form['advanced']);
-hide($form['actions']);
-
-?>
-<div class="layout-node-form clearfix">
- <div class="layout-region layout-region-node-main">
- <?php print drupal_render_children($form); ?>
- </div>
-
- <div class="layout-region layout-region-node-secondary">
- <?php print render($form['advanced']); ?>
- </div>
-
- <div class="layout-region layout-region-node-footer">
- <?php print render($form['actions']); ?>
- </div>
-</div>
diff --git a/core/modules/node/templates/node.html.twig b/core/modules/node/templates/node.html.twig
index 0b3a322..d28b880 100644
--- a/core/modules/node/templates/node.html.twig
+++ b/core/modules/node/templates/node.html.twig
@@ -4,8 +4,25 @@
* Default theme implementation to display a node.
*
* Available variables:
- * - label: the title of the node.
- * - content: node items. Use {{ content }} to print them all,
+ * - node: Full node entity.
+ * - type: The type of the node, for example, "page" or "article".
+ * - uid: The user ID of the node author.
+ * - created: Formatted creation date. Preprocess functions can reformat it by
+ * calling format_date() with the desired parameters on
+ * $variables['node']->created.
+ * - promote: 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
+ * - status: Whether the node is published.
+ * - comment: A value representing the comment status of the current node. May
+ * be one of the following:
+ * - 0: The comment form and any existing comments are hidden.
+ * - 1: Comments are closed. No new comments may be posted, but existing
+ * comments are displayed.
+ * - 2: Comments are open on this node.
+ * - comment_count: Number of comments attached to the node.
+ * - 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
* {% hide(content.field_example) %} to temporarily suppress the printing
* of a given element.
@@ -18,40 +35,28 @@
* - 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:
- * - node: The current template type; for example, "theming hook".
+ * - attributes: HTML attributes for the containing element.
+ * 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
* name will often be in a short form of the human readable label.
- * - view-mode-[view_mode]: The View Mode of the node; for example, "teaser"
- * or "full".
- * - preview: Nodes in preview mode.
+ * - view-mode-[view_mode]: The View Mode of the node; for example, a teaser
+ * would result in: "view-mode-teaser", and full: "view-mode-full".
+ * - preview: Whether a node is in preview mode.
* The following are controlled through the node publishing options.
- * - promoted: Nodes promoted to the front page.
- * - sticky: Nodes ordered above other non-sticky nodes in teaser
+ * - promoted: Appears on nodes promoted to the front page.
+ * - sticky: Appears on nodes ordered above other non-sticky nodes in teaser
* listings.
- * - unpublished: Unpublished nodes visible only to administrators.
+ * - unpublished: Appears on unpublished nodes visible only to site admins.
* - 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.
- *
- * Other variables:
- * - node: Fully loaded node entity.
- * - 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.
- *
- * Node status variables:
* - 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'.
- * - promote: Flag for front page promotion state.
- * - sticky: Flag for sticky post setting.
- * - status: Flag for published status.
- * - comment: State of comment settings for the node.
* - 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.
@@ -60,16 +65,20 @@
* - is_admin: Flag for admin user status. Will be true when the current user
* is an administrator.
*
- * Field variables: for each field instance attached to the node a corresponding
- * variable is defined; for example, $node->body becomes body. When needing to
+ * In field variables, each field instance attached to the node a corresponding
+ * variable is defined; for example, 'node.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.
+ * desired field language; for example, 'node.body.en', thus overriding any
+ * language negotiation rule that may have been applied previously.
*
* @see template_preprocess()
* @see template_preprocess_node()
*
+ * @todo Remove the id attribute (or make it a class), because if that gets
+ * rendered twice on a page this is invalid CSS for example: two lists
+ * in different view modes.
+ *
* @ingroup themeable
*/
#}
@@ -90,7 +99,7 @@
</footer>
{% endif %}
- <div class="content"{{ content_attributes }}>
+ <div{{ content_attributes }}>
{# 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 35cd730..0000000
--- a/core/modules/node/templates/node.tpl.php
+++ /dev/null
@@ -1,103 +0,0 @@
-<?php
-
-/**
- * @file
- * Default theme implementation to display a node.
- *
- * Available variables:
- * - $label: the (sanitized) title of the node.
- * - $content: An array of node items. Use render($content) to print them all,
- * or print a subset such as render($content['field_example']). Use
- * hide($content['field_example']) to temporarily suppress the printing of a
- * given element.
- * - $user_picture: The node author's picture. Use render() to print it.
- * - $date: Formatted creation date. Preprocess functions can reformat it by
- * calling format_date() with the desired parameters on the $created variable.
- * - $name: Themed username of node author output from theme_username().
- * - $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: An instance of Attributes class that can be manipulated as an
- * array and printed as a string.
- * It includes the 'class' information, which includes:
- * - 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
- * name will often be in a short form of the human readable label.
- * - view-mode-[view_mode]: The View Mode of the node; for example, "teaser"
- * or "full".
- * - preview: Nodes in preview mode.
- * The following are controlled through the node publishing options.
- * - promoted: Nodes promoted to the front page.
- * - sticky: Nodes ordered above other non-sticky nodes in teaser
- * listings.
- * - unpublished: Unpublished nodes visible only to administrators.
- * - $title_prefix (array): An array containing additional output populated by
- * modules, intended to be displayed in front of the main title tag that
- * appears in the template.
- * - $title_suffix (array): An array containing additional output populated by
- * modules, intended to be displayed after the main title tag that appears in
- * the template.
- *
- * Other variables:
- * - $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 in Unix timestamp.
- *
- * Node status variables:
- * - $view_mode: View mode; for example, "teaser" or "full".
- * - $teaser: Flag for the teaser state (shortcut for $view_mode == 'teaser').
- * - $page: Flag for the full page state.
- * - $promote: Flag for front page promotion state.
- * - $sticky: Flags for sticky post setting.
- * - $status: Flag for published status.
- * - $comment: State of comment settings for the node.
- * - $is_front: Flags true when presented in the front page.
- * - $logged_in: Flags true when the current user is a logged-in member.
- * - $is_admin: Flags true when the current user is an administrator.
- *
- * Field variables: for each field instance attached to the node a corresponding
- * variable is defined; for example, $node->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
- */
-?>
-<article id="node-<?php print $node->nid; ?>" class="<?php print $attributes['class']; ?> clearfix"<?php print $attributes; ?>>
-
- <?php print render($title_prefix); ?>
- <?php if (!$page): ?>
- <h2<?php print $title_attributes; ?>><a href="<?php print $node_url; ?>" rel="bookmark"><?php print $label; ?></a></h2>
- <?php endif; ?>
- <?php print render($title_suffix); ?>
-
- <?php if ($display_submitted): ?>
- <footer>
- <?php print render($user_picture); ?>
- <p class="submitted"><?php print $submitted; ?></p>
- </footer>
- <?php endif; ?>
-
- <div class="content"<?php print $content_attributes; ?>>
- <?php
- // We hide the comments and links now so that we can render them later.
- hide($content['comments']);
- hide($content['links']);
- print render($content);
- ?>
- </div>
-
- <?php print render($content['links']); ?>
- <?php print render($content['comments']); ?>
-
-</article>
diff --git a/core/modules/rdf/rdf.module b/core/modules/rdf/rdf.module
index 3783f6b..aaea6bb 100644
--- a/core/modules/rdf/rdf.module
+++ b/core/modules/rdf/rdf.module
@@ -492,7 +492,7 @@ function rdf_preprocess_html(&$variables) {
}
/**
- * Implements hook_preprocess_HOOK() for node.tpl.php.
+ * Implements hook_preprocess_HOOK() for node.html.twig.
*/
function rdf_preprocess_node(&$variables) {
// Adds RDFa markup to the node container. The about attribute specifies the
@@ -509,7 +509,7 @@ function rdf_preprocess_node(&$variables) {
$variables['title_attributes']['property'] = empty($variables['node']->rdf_mapping['title']['predicates']) ? NULL : $variables['node']->rdf_mapping['title']['predicates'];
$variables['title_attributes']['datatype'] = '';
- // In full node mode, the title is not displayed by node.tpl.php so it is
+ // In full node mode, the title is not displayed by node.html.twig so it is
// added in the <head> tag of the HTML page.
if ($variables['page']) {
$element = array(
@@ -557,7 +557,7 @@ function rdf_preprocess_node(&$variables) {
$variables['content']['links']['comment']['#links']['comment-comments']['attributes'] += $comment_count_attributes;
}
// In full node view, the number of comments is not displayed by
- // node.tpl.php so it is expressed in RDFa in the <head> tag of the HTML
+ // node.html.twig so it is expressed in RDFa in the <head> tag of the HTML
// page.
if ($variables['page'] && user_access('access comments')) {
$element = array(
@@ -843,8 +843,8 @@ function rdf_preprocess_image(&$variables) {
* - context: An array of context information about the content to be wrapped:
* - hook: The theme hook that will use the wrapped content. This
* corresponds to the key within the theme registry for this template.
- * For example, if this content is about to be used in node.tpl.php or
- * node-[type].tpl.php, then the 'hook' is 'node'.
+ * For example, if this content is about to be used in node.html.twig or
+ * node-[type].html.twig, then the 'hook' is 'node'.
* - variable_name: The name of the variable by which the template will
* refer to this content. Each template file has documentation about
* the variables it uses. For example, if this function is called in