diff --git a/core/modules/node/node.module b/core/modules/node/node.module index 9a9f154..bd72e2d 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -155,10 +155,12 @@ 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_recent_block' => array( 'variables' => array('nodes' => NULL), diff --git a/core/modules/node/node.pages.inc b/core/modules/node/node.pages.inc index ad96476..d223fa5 100644 --- a/core/modules/node/node.pages.inc +++ b/core/modules/node/node.pages.inc @@ -14,31 +14,27 @@ use Drupal\node\NodeInterface; /** - * 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']; - - 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; } /** @@ -73,41 +69,37 @@ function node_preview(NodeInterface $node, array &$form_state) { } /** - * Returns HTML for a node preview for display during node creation and editing. + * Prepares variables for node preview templates. * - * @param $variables + * Default template: node-preview.html.twig. + * + * @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) { + // 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']) { 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..7323896 --- /dev/null +++ b/core/modules/node/templates/node-add-list.html.twig @@ -0,0 +1,32 @@ +{# +/** + * @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_node_add_list() + * + * @ingroup themeable + */ +#} +{% if types is not empty %} +
+ {% for type in types %} +
{{ type.add_link }}
+
{{ type.description }}
+ {% endfor %} +
+{% else %} +

+ {% set create_content = url('admin/structure/types/add') %} + {% trans %} + You have not created any content types yet. Go to the content type creation page to add a new content type. + {% endtrans %} +

+{% endif %} 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..1bc3441 --- /dev/null +++ b/core/modules/node/templates/node-preview.html.twig @@ -0,0 +1,23 @@ +{# +/** + * @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_node_preview() + * + * @ingroup themeable + */ +#} +{% if preview_teaser %} +

{{ "Preview trimmed version"|t }}

+ {{ teaser }} +

{{ "Preview full version"|t }}

+{% endif %} +{{ full }}