This patch includes the node preview preprocess function in addition to a few tweaks to the existing node-preview.html.twig file. Not sure if I should include that with the patch or not. Most of the existing template has been retained, some of the logic for display has changed to account for different variables passed to the template.

Comments

vlad.dancer’s picture

Status: Needs review » Reviewed & tested by the community

Good job!

steveoliver’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new2.37 KB

Maybe this would be just a little cleaner?

steveoliver’s picture

This is what my patch addresses:

+++ b/core/modules/node/node.pages.inc
@@ -186,6 +186,29 @@ function theme_node_preview($variables) {
+    $variables['preview_teaser'] = TRUE;
+  }
+  else {
+    $variables['preview_teaser'] = FALSE;
+  }

We always set variables.

+++ b/core/modules/node/node.pages.inc
@@ -186,6 +186,26 @@ function theme_node_preview($variables) {
+function template_preprocess_node_preview(&$variables) {
+  $node = $variables['node'];
+
+  // Render trimmed teaser version of the post.
+  $elements = node_view(clone $node, 'teaser');
+  $variables['teaser']= drupal_render($elements);
+  // Render full version of the post.
+  $elements = node_view($node, 'full');
+  $variables['full'] = drupal_render($elements);
+

Use unique variable names here.

+++ b/core/themes/stark/templates/node/node-preview.html.twig
@@ -6,21 +6,21 @@
  * Available variables:
- * - preview: Preview version of the node.
+ * - teaser: Trimmed teaser version of the node.
  * - full: Full version of the node.
+ * - preview_teaser_version: Whether or not to show a trimmed teaser version.
  *
  * @see template_preprocess
+ * @see template_preprocess_node_preview()
  *
  * @ingroup themeable

Unnecessarily long variables name.

Cleanup @see syntax.

+++ b/core/themes/stark/templates/node/node-preview.html.twig
@@ -6,21 +6,21 @@
 <div class="node-preview-container">
-  {% if preview %}
+  {% if preview_teaser_version is defined %}

Unnecessary check, know variables should always be defined.

EVIIILJ’s picture

StatusFileSize
new2.36 KB

@steveoliver: Thank you for clarifying all your suggestions. They all make perfect sense, in fact I was battling them myself initially while creating the first patch but elected to go with similarities from the original theme_node_preview function. I like the alternative you suggested as well :)

Unnecessary check, known variables should always be defined

Great to know, I will adopt this standard in future conversions I take on.

Attached is an updated patch including the suggested changes.

steveoliver’s picture

Title: Create preprocess function for theme_node_preview » Create preprocess function for theme('node_preview')
Status: Needs review » Closed (fixed)

Thanks, EVIIILJ. Committed in 2b55585.

decafdennis’s picture

Status: Closed (fixed) » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Project: » Lost & found issues

This issue’s project has disappeared. Most likely, it was a sandbox project, which can be deleted by its maintainer. See the Lost & found issues project page for more details. (The missing project ID was 1750250)