summaryrefslogtreecommitdiff
path: root/includes
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2011-02-04 21:36:31 +0000
committerDries Buytaert <dries@buytaert.net>2011-02-04 21:36:31 +0000
commit2b3c728a56c4d081039e2bff0f5615a970a60f94 (patch)
tree2a484e6922bcf954df1fbb93191ba73c68c6ff16 /includes
parent25a4309ed0f7d9401e0a8b0fe560e77af6c684ce (diff)
downloadbrdo-2b3c728a56c4d081039e2bff0f5615a970a60f94.tar.gz
brdo-2b3c728a56c4d081039e2bff0f5615a970a60f94.tar.bz2
- Patch #859602 by catch, bfroehle: #cache does not record the #attached declared in child elements.
Diffstat (limited to 'includes')
-rw-r--r--includes/common.inc48
1 files changed, 46 insertions, 2 deletions
diff --git a/includes/common.inc b/includes/common.inc
index 62a5037f0..2ab991433 100644
--- a/includes/common.inc
+++ b/includes/common.inc
@@ -5827,8 +5827,9 @@ function drupal_render_cache_set(&$markup, $elements) {
// be retrieved and used.
$data['#markup'] = &$markup;
// Persist attached data associated with this element.
- if (isset($elements['#attached'])) {
- $data['#attached'] = $elements['#attached'];
+ $attached = drupal_render_collect_attached($elements, TRUE);
+ if ($attached) {
+ $data['#attached'] = $attached;
}
$bin = isset($elements['#cache']['bin']) ? $elements['#cache']['bin'] : 'cache';
$expire = isset($elements['#cache']['expire']) ? $elements['#cache']['expire'] : CACHE_PERMANENT;
@@ -5836,6 +5837,49 @@ function drupal_render_cache_set(&$markup, $elements) {
}
/**
+ * Collect #attached for an element and all child elements into a single array.
+ *
+ * When caching elements, it is necessary to collect all libraries, javascript
+ * and CSS into a single array, from both the element itself and all child
+ * elements. This allows drupal_render() to add these back to the page when the
+ * element is returned from cache.
+ *
+ * @param $elements
+ * The element to collect #attached from.
+ * @param $return
+ * Whether to return the attached elements and reset the internal static.
+ *
+ * @return
+ * The #attached array for this element and its descendants.
+ */
+function drupal_render_collect_attached($elements, $return = FALSE) {
+ $attached = &drupal_static(__FUNCTION__, array());
+
+ // Collect all #attached for this element.
+ if (isset($elements['#attached'])) {
+ foreach ($elements['#attached'] as $key => $value) {
+ if (!isset($attached[$key])) {
+ $attached[$key] = array();
+ }
+ $attached[$key] = array_merge($attached[$key], $value);
+ }
+ }
+ if ($children = element_children($elements)) {
+ foreach ($children as $child) {
+ drupal_render_collect_attached($elements[$child]);
+ }
+ }
+
+ // If this was the first call to the function, return all attached elements
+ // and reset the static cache.
+ if ($return) {
+ $return = $attached;
+ $attached = array();
+ return $return;
+ }
+}
+
+/**
* Prepare an element for caching based on a query. This smart caching strategy
* saves Drupal from querying and rendering to HTML when the underlying query is
* unchanged.