commit e60476a1b54f94eb58e098119f75784acd771781 Author: Shane Auckland Date: Tue May 7 10:48:37 2013 +0100 1987406 diff --git a/core/modules/node/content_types.inc b/core/modules/node/content_types.inc index f8b144a..7c9810a 100644 --- a/core/modules/node/content_types.inc +++ b/core/modules/node/content_types.inc @@ -75,27 +75,20 @@ function node_overview_types() { } /** - * Returns HTML for a node type description for the content type admin page. + * Prepares variables for node type description templates. * - * @param $variables + * Default template: node-admin-overview.html.twig. + * + * @param array $variables * An associative array containing: * - name: The human-readable name of the content type. * - type: An object containing the 'type' (machine name) and 'description' of * the content type. - * - * @return string - * An HTML-formatted string of the description for this node type. - * - * @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.module b/core/modules/node/node.module index 0d92454..6ac37e2 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -157,20 +157,25 @@ function node_theme() { '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', @@ -1907,23 +1912,27 @@ function node_get_recent($number = 10) { } /** - * Returns HTML for a list of recent content. + * Prepares variables for list of recent content templates. * - * @param $variables + * Default template: node-recent-content.html.twig. + * + * @param array $variables * An associative array containing: * - nodes: An array of recent node entities. * - * @ingroup themeable + * @see template_preprocess_node_recent_content() */ -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) { $row = array(); $row[] = array( - 'data' => theme('node_recent_content', array('node' => $node)), + 'data' => array( + '#theme' => 'node_recent_content', + '#node' => $node, + ), 'class' => 'title-author', ); if (node_access('update', $node)) { @@ -1942,35 +1951,42 @@ function theme_node_recent_block($variables) { } 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. + * Prepares variables for recently created node templates. * - * @param $variables + * Default template: node-recent-content.twig. + * + * @param array $variables * An associative array containing: * - node: A node entity. * - * @ingroup themeable + * @see template_preprocess_node_recent_block() */ -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 863babd..517c615 100644 --- a/core/modules/node/node.pages.inc +++ b/core/modules/node/node.pages.inc @@ -56,32 +56,27 @@ function node_add_page() { } /** - * Returns HTML for a list of available node types for node creation. + * Prepares variables for list of available node type templates. * - * @param $variables + * Default template: node-add-list.html.twig. + * + * @param array $variables * An associative array containing: * - content: An array of content types. * * @see 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) { + $variables['types'] = array(); + if (!empty($variables['content'])) { + foreach ($variables['content'] as $type) { + $variables['types'][$type->type] = array( + 'type' => $type->type, + 'add_link' => l($type->name, 'node/add/' . $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,41 +152,36 @@ function node_preview(EntityInterface $node) { } /** - * Returns HTML for a node preview for display during node creation and editing. + * Prepares variables for node preview templates. + * + * Default template: node-preview.html.twig. * - * @param $variables + * @param array $variables * An associative array containing: * - node: The node entity which is being previewed. * * @see NodeFormController::preview() * @see node_preview() - * - * @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) { - 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; + // Render trimmed teaser version of the post. + $node_teaser = node_view($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; + + // Display a preview of the teaser only if the content of the teaser is + // different to the full post. + if ($variables['teaser'] != $variables['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..60b732d --- /dev/null +++ b/core/modules/node/templates/node-add-list.html.twig @@ -0,0 +1,28 @@ +{# +/** + * @file + * Default theme implementation to list node types available for adding content. + * + * This list is displayed on the Add content admin page. + * + * Available variables: + * - types: A list of content types, each with the following properties: + * - add_link: Link to create a piece of content of this type. + * - description: Description of this type of content. + * + * @see template_preprocess() + * @see template_preprocess_node_add_list() + * + * @ingroup themeable + */ +#} +{% if types is not empty %} +
+ {% 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..7438945 --- /dev/null +++ b/core/modules/node/templates/node-admin-overview.html.twig @@ -0,0 +1,20 @@ +{# +/** + * @file + * Default theme implementation for a node type description. + * + * This description is used for the content types 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..aa8ec0e --- /dev/null +++ b/core/modules/node/templates/node-preview.html.twig @@ -0,0 +1,24 @@ +{# +/** + * @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 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..092326d --- /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..f1a6d34 --- /dev/null +++ b/core/modules/node/templates/node-recent-content.html.twig @@ -0,0 +1,18 @@ +{# +/** + * @file + * Default theme implementation for a node 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 }}