Forked from filiphazardous/viewsreference_add_entity_to_context-2.patch
Last active
April 12, 2018 21:43
-
-
Save michaellopez/e4746242d8ab487725a01a07db623cbb to your computer and use it in GitHub Desktop.
Add nodes in block to context for viewsreference v2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/Plugin/Field/FieldFormatter/ViewsReferenceFieldFormatter.php b/src/Plugin/Field/FieldFormatter/ViewsReferenceFieldFormatter.php | |
index 7371caf..36252cf 100644 | |
--- a/src/Plugin/Field/FieldFormatter/ViewsReferenceFieldFormatter.php | |
+++ b/src/Plugin/Field/FieldFormatter/ViewsReferenceFieldFormatter.php | |
@@ -100,6 +100,9 @@ class ViewsReferenceFieldFormatter extends FormatterBase { | |
} | |
$node = \Drupal::routeMatch()->getParameter('node'); | |
+ if ($items->getEntity() instanceof \Drupal\node\NodeInterface) { | |
+ $node = $items->getEntity(); | |
+ } | |
$token_service = \Drupal::token(); | |
if (is_array($arguments)) { | |
foreach ($arguments as $index => $argument) { | |
@@ -131,6 +134,7 @@ class ViewsReferenceFieldFormatter extends FormatterBase { | |
} | |
$elements[$delta]['contents'] = $view->buildRenderable($display_id); | |
+ unset($elements[$delta]['contents']['#cache']); | |
} | |
return $elements; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment