From e45a3a65f0a46eb11207bc188c65057cdee3f265 Mon Sep 17 00:00:00 2001 From: Lukas von Blarer Date: Thu, 9 Jun 2016 03:55:12 +0200 Subject: [PATCH 1/3] Adding cache tags --- src/Plugin/Field/FieldFormatter/ViewfieldDefaultFormatter.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Plugin/Field/FieldFormatter/ViewfieldDefaultFormatter.php b/src/Plugin/Field/FieldFormatter/ViewfieldDefaultFormatter.php index c4b2b14..7374664 100644 --- a/src/Plugin/Field/FieldFormatter/ViewfieldDefaultFormatter.php +++ b/src/Plugin/Field/FieldFormatter/ViewfieldDefaultFormatter.php @@ -46,7 +46,11 @@ public function viewElements(FieldItemListInterface $items, $langcode) { '#entity_id' => $entity->id(), '#entity' => $entity, '#theme' => 'viewfield_formatter_default', + '#cache' => [ + 'tags' => $view->getCacheTags() + ], ); + kint($elements); } return $elements; } From ebd4c4481c871e3d93450295ce7aa0e2dfc57313 Mon Sep 17 00:00:00 2001 From: Lukas von Blarer Date: Thu, 9 Jun 2016 12:16:06 +0200 Subject: [PATCH 2/3] Remove kint() --- src/Plugin/Field/FieldFormatter/ViewfieldDefaultFormatter.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Plugin/Field/FieldFormatter/ViewfieldDefaultFormatter.php b/src/Plugin/Field/FieldFormatter/ViewfieldDefaultFormatter.php index 7374664..66397a7 100644 --- a/src/Plugin/Field/FieldFormatter/ViewfieldDefaultFormatter.php +++ b/src/Plugin/Field/FieldFormatter/ViewfieldDefaultFormatter.php @@ -50,7 +50,6 @@ public function viewElements(FieldItemListInterface $items, $langcode) { 'tags' => $view->getCacheTags() ], ); - kint($elements); } return $elements; } From ce911e46b76201b040e0853fe9761f7462702365 Mon Sep 17 00:00:00 2001 From: Lukas von Blarer Date: Fri, 29 Jul 2016 14:08:54 +0200 Subject: [PATCH 3/3] Using buildRenderable() to add cache metadata --- .../Field/FieldFormatter/ViewfieldDefaultFormatter.php | 5 ++--- viewfield.module | 4 +--- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/Plugin/Field/FieldFormatter/ViewfieldDefaultFormatter.php b/src/Plugin/Field/FieldFormatter/ViewfieldDefaultFormatter.php index 66397a7..b0f1a13 100644 --- a/src/Plugin/Field/FieldFormatter/ViewfieldDefaultFormatter.php +++ b/src/Plugin/Field/FieldFormatter/ViewfieldDefaultFormatter.php @@ -35,9 +35,11 @@ public function viewElements(FieldItemListInterface $items, $langcode) { $entity = $item->getEntity(); list($view_name, $view_display) = explode('|', $item->vname, 2); $view = Views::getView($view_name); + $build = $view->buildRenderable($view_display, _viewfield_get_view_args($item->vargs, $entity->getEntityTypeId(), $entity)); $elements[$delta] = array( '#type' => 'viewfield', '#view' => $view, + '#build' => $build, '#access' => $view && $view->access($view_display), '#view_name' => $view_name, '#view_display' => $view_display, @@ -46,9 +48,6 @@ public function viewElements(FieldItemListInterface $items, $langcode) { '#entity_id' => $entity->id(), '#entity' => $entity, '#theme' => 'viewfield_formatter_default', - '#cache' => [ - 'tags' => $view->getCacheTags() - ], ); } return $elements; diff --git a/viewfield.module b/viewfield.module index 56d3c68..3a929ae 100644 --- a/viewfield.module +++ b/viewfield.module @@ -24,9 +24,7 @@ function viewfield_theme() { */ function viewfield_preprocess_viewfield_formatter_default(&$variables) { $element = $variables['element']; - $view_el = $element['#view']->preview($element['#view_display'], array($element['#view_arguments'])); - $output = render ($view_el); - $variables['output'] = $output; + $variables['output'] = $element['#build']; } /**