Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaellopez/e4746242d8ab487725a01a07db623cbb to your computer and use it in GitHub Desktop.
Save michaellopez/e4746242d8ab487725a01a07db623cbb to your computer and use it in GitHub Desktop.
Add nodes in block to context for viewsreference v2
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