You are here

function lazy_pane_lazy_cache_get in Lazy Pane 7

A mock cache retrieval function that prevents the pane from rendering and stores its data, for later, on demand rendering.

1 string reference to 'lazy_pane_lazy_cache_get'
lazy.inc in plugins/cache/lazy.inc

File

plugins/cache/lazy.inc, line 25

Code

function lazy_pane_lazy_cache_get($conf, $display, $args, $contexts, $pane = NULL) {

  // Since we can't accurately predict when the cache is to be expired set it
  // permanent and overwrite as many times as necessary.
  $cache_expiry = CACHE_PERMANENT;

  // Generate a unique ID for this lazy pane.
  $lazy_pane_id = lazy_pane_lazy_id($display, $pane);

  // Save the arguments to the cache that will be used to generate the pane.
  $data = array(
    'conf' => $conf,
    'display' => $display,
    'args' => $args,
    'contexts' => $contexts,
    'pane' => $pane,
    'path' => current_path(),
  );
  cache_set($lazy_pane_id, $data, 'cache', $cache_expiry);

  // Add the required javascript libraries for placeholder replacement unless
  // we are already within a lazy pane request, in which case the libs and
  // are settings are already there.
  if (!lazy_pane_is_lazy_request()) {
    $module_path = drupal_get_path('module', 'lazy_pane');
    drupal_add_library('system', 'drupal.ajax');
    drupal_add_js($module_path . '/js/lazy-pane.js');
    drupal_add_css($module_path . '/css/lazy-pane.css');
    $settings = array(
      'lazy_pane' => array(
        'current_path' => current_path(),
      ),
    );
    drupal_add_js($settings, 'setting');
  }

  // Generate the placeholder and its attributes.
  $attr = array(
    'class' => 'lazy-pane-placeholder',
    'data-lazy-pane-id' => $lazy_pane_id,
    'data-lazy-pane-load-strategy' => $conf['load_strategy'],
  );
  $placeholder_contents = '';
  if (!empty($conf['show_spinner'])) {
    $placeholder_contents .= '<span class="lazy-pane-spinner"></span>';
  }
  if (!empty($conf['load_text'])) {
    $placeholder_contents .= '<p class="lazy-pane-text">' . check_plain(ctools_context_keyword_substitute($conf['load_text'], array(), $contexts)) . '</p>';
  }
  $fake_content = new stdClass();
  $fake_content->type = empty($pane) ? '' : $pane->type;
  $fake_content->subtype = empty($pane) ? '' : $pane->subtype;
  $fake_content->content = '<div ' . drupal_attributes($attr) . '>' . $placeholder_contents . '</div>';
  $fake_cache = new lazy_pane_lazy_cache_object();
  $fake_cache->content = $fake_content;

  // If we are dealing with a display instead of a pane, panels expects a
  // content string and not a pane object.
  if (empty($pane)) {
    $fake_cache->content = $fake_content->content;
  }
  return $fake_cache;
}