You are here

function panels_cache_object::cache in Panels 7.3

Same name and namespace in other branches
  1. 5.2 includes/plugins.inc \panels_cache_object::cache()
  2. 6.3 includes/plugins.inc \panels_cache_object::cache()
  3. 6.2 includes/plugins.inc \panels_cache_object::cache()

Set the object for storing. This overwrites.

File

includes/plugins.inc, line 149
Contains helper code for plugins and contexts.

Class

panels_cache_object
An object to hold caching information while it is happening.

Code

function cache() {
  if ($this->ready) {
    return;
  }
  $this->ready = TRUE;

  // Simple replacement for head.
  $this->head = str_replace($this->head, '', drupal_add_html_head());

  // Slightly less simple for CSS:
  $css = drupal_add_css();
  $start = $this->css;
  $this->css = array();
  foreach ($css as $name => $data) {
    if (!isset($start[$name])) {
      $this->css[$name] = $data;
    }
  }
  $js = drupal_add_js();
  $start = $this->js;
  $this->js = array();

  // Use the advanced mapping function from Drupal >= 7.23 if available.
  $array_mapping_func = function_exists('drupal_array_diff_assoc_recursive') ? 'drupal_array_diff_assoc_recursive' : 'array_diff_assoc';

  // If there are any differences between the old and the new javascript then
  // store them to be added later.
  if ($diff = $array_mapping_func($js, $start)) {

    // Iterate over the diff to ensure we keep the keys on merge and don't add
    // unnecessary items.
    foreach ($diff as $key => $diff_data) {

      // Special case the settings key and get the difference of the data.
      if ($key === 'settings') {

        // Iterate over the diff to ensure we keep the keys on merge and don't
        // add unnecessary items.
        if (isset($diff[$key]['data'])) {
          foreach ($diff[$key]['data'] as $settings_key => $settings_data) {

            // Merge the changes with the base to get a complete settings
            // array.
            $this->js[$key]['data'][] = drupal_array_merge_deep($settings_data, $diff[$key]['data'][$settings_key]);
          }
        }
      }
      else {
        $this->js[$key] = $diff_data;

        // Check if the key was present already and if so merge the changes
        // with the original data to get the full settings array.
        if (isset($start[$key])) {
          $this->js[$key] = drupal_array_merge_deep($start[$key], $this->js[$key]);
        }
      }
    }
  }

  // And for tokens:
  $tokens = ctools_set_page_token();
  foreach ($this->tokens as $token => $argument) {
    if (isset($tokens[$token])) {
      unset($tokens[$token]);
    }
  }
  $this->tokens = $tokens;
}