You are here

public function views_plugin_cache::gather_headers in Views (for Drupal 7) 7.3

Same name and namespace in other branches
  1. 6.3 plugins/views_plugin_cache.inc \views_plugin_cache::gather_headers()
  2. 6.2 plugins/views_plugin_cache.inc \views_plugin_cache::gather_headers()

Gather out of band data, compare it to the start data and store the diff.

1 call to views_plugin_cache::gather_headers()
views_plugin_cache::cache_set in plugins/views_plugin_cache.inc
Save data to the cache.

File

plugins/views_plugin_cache.inc, line 200
Definition of views_plugin_cache.

Class

views_plugin_cache
The base plugin to handle caching.

Code

public function gather_headers() {

  // Simple replacement for head.
  if (isset($this->storage['head'])) {
    $this->storage['head'] = str_replace($this->storage['head'], '', drupal_add_html_head());
  }
  else {
    $this->storage['head'] = '';
  }

  // Check if the advanced mapping function of D 7.23 is available.
  $array_mapping_func = function_exists('drupal_array_diff_assoc_recursive') ? 'drupal_array_diff_assoc_recursive' : 'array_diff_assoc';

  // Slightly less simple for CSS.
  $css = drupal_add_css();
  $css_start = isset($this->storage['css']) ? $this->storage['css'] : array();
  $this->storage['css'] = $this
    ->assetDiff($css, $css_start, $array_mapping_func);

  // Get JavaScript after/before views renders.
  $js = drupal_add_js();
  $js_start = isset($this->storage['js']) ? $this->storage['js'] : array();

  // If there are any differences between the old and the new JavaScript then
  // store them to be added later.
  $this->storage['js'] = $this
    ->assetDiff($js, $js_start, $array_mapping_func);

  // Special case the settings key and get the difference of the data.
  $settings = isset($js['settings']['data']) ? $js['settings']['data'] : array();
  $settings_start = isset($js_start['settings']['data']) ? $js_start['settings']['data'] : array();
  $this->storage['js']['settings'] = $array_mapping_func($settings, $settings_start);

  // Get difference of HTTP headers.
  $this->storage['headers'] = $array_mapping_func(drupal_get_http_header(), $this->storage['headers']);
}