summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormicropat2016-06-10 23:32:25 -0700
committermicropat2016-06-10 23:32:25 -0700
commit8b84be840f1b4266b27157f058605c30a094009a (patch)
treed143b367bf71306a24308ea3e352b38290226231
parentc7d091abd767a81c0785dac84890985278c73f37 (diff)
Add cache contexts to vary caching by URL
Fixes issue where the AddToAny instance (an AddToAny Block, for example) was rendered with static attributes (sharing whichever URL/title was cached first) instead of dynamic attributes (sharing the current node's URL/title). Issue #2742513
-rw-r--r--src/Plugin/Block/AddToAnyBlock.php6
-rw-r--r--src/Plugin/DsField/AddToAnyField.php5
2 files changed, 7 insertions, 4 deletions
diff --git a/src/Plugin/Block/AddToAnyBlock.php b/src/Plugin/Block/AddToAnyBlock.php
index 39db5a7..41b07c9 100644
--- a/src/Plugin/Block/AddToAnyBlock.php
+++ b/src/Plugin/Block/AddToAnyBlock.php
@@ -21,11 +21,11 @@ class AddToAnyBlock extends BlockBase {
$node = \Drupal::routeMatch()->getParameter('node');
return array(
- // Not using #markup because data attribute name gets mangled
- // @see https://www.drupal.org/node/2609928
- // '#markup' => addtoany_create_node_buttons($node),
'#addtoany_html' => addtoany_create_node_buttons($node),
'#theme' => 'addtoany_standard',
+ '#cache' => array(
+ 'contexts' => array('url'),
+ ),
);
}
diff --git a/src/Plugin/DsField/AddToAnyField.php b/src/Plugin/DsField/AddToAnyField.php
index 8a25f7f..251709e 100644
--- a/src/Plugin/DsField/AddToAnyField.php
+++ b/src/Plugin/DsField/AddToAnyField.php
@@ -28,8 +28,11 @@ class AddToAnyField extends DsFieldBase {
$node = \Drupal::routeMatch()->getParameter('node');
return array(
- '#theme' => 'addtoany_standard',
'#addtoany_html' => addtoany_create_node_buttons($node),
+ '#theme' => 'addtoany_standard',
+ '#cache' => array(
+ 'contexts' => array('url'),
+ ),
);
}
}