You are here

function cache_actions_rules_cache_settings_form in Cache Actions 7.2

Same name and namespace in other branches
  1. 6.2 plugins/cache/rules.inc \cache_actions_rules_cache_settings_form()
  2. 7 plugins/cache/rules.inc \cache_actions_rules_cache_settings_form()

Provide a form for the cache settings.

Parameters

array $conf: The current configuration.

stdClass $display: The display object

string $pid: The pane pid.

1 string reference to 'cache_actions_rules_cache_settings_form'
rules.inc in plugins/cache/rules.inc
Provides a simple time-based caching option for panel panes.

File

plugins/cache/rules.inc, line 159
Provides a simple time-based caching option for panel panes.

Code

function cache_actions_rules_cache_settings_form(&$conf, $display, $pid) {
  $form = array();
  $form['granularity'] = array(
    '#title' => t('Granularity'),
    '#type' => 'select',
    '#options' => array(
      'args' => t('Arguments'),
      'context' => t('Context'),
      'none' => t('None'),
    ),
    '#description' => t('If "arguments" are selected, this content will be cached per individual argument to the entire display; if "contexts" are selected, this content will be cached per unique context in the pane or display; if "neither" there will be only one cache for this pane.'),
    '#default_value' => $conf['granularity'],
  );
  $form['language'] = array(
    '#title' => t('Cache per interface language'),
    '#type' => 'checkbox',
    '#default_value' => $conf['language'],
    '#description' => t('Select this if you want to cache content per language'),
  );
  $form['language_content'] = array(
    '#title' => t('Cache per content language'),
    '#type' => 'checkbox',
    '#default_value' => $conf['language_content'],
    '#description' => t('Select this if you want to cache content per language'),
  );
  $form['advanced'] = array(
    '#type' => 'fieldset',
    '#title' => t('Advanced'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );

  // If we encounter an old value, we should convert it to a unique id instead.
  if (!empty($conf['cache_key']) && $conf['cache_key'] == $display->cache_key) {
    $conf['cache_key'] = uniqid();
  }
  $form['advanced']['cache_key'] = array(
    '#type' => 'textfield',
    '#required' => TRUE,
    '#title' => t('Cache key'),
    '#default_value' => empty($conf['cache_key']) ? uniqid() : $conf['cache_key'],
    '#description' => t('This is the key that will be used.
      The granularity and language settings will be appended after this key.
      You can use substitutions here.'),
  );
  $form['advanced']['substitute'] = array(
    '#type' => 'checkbox',
    '#title' => t('Use context keywords'),
    '#description' => t('If checked, context keywords will be substituted in this content.
      This is not compatible with the standard cache actions clear pane action!'),
    '#default_value' => !empty($conf['substitute']),
  );
  $form['advanced']['contexts'] = array(
    '#title' => t('Substitutions'),
    '#type' => 'fieldset',
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $rows = array();
  foreach ($display->context as $context) {
    foreach (ctools_context_get_converters('%' . check_plain($context->keyword) . ':', $context) as $keyword => $title) {
      $rows[] = array(
        check_plain($keyword),
        t('@identifier: @title', array(
          '@title' => $title,
          '@identifier' => $context->identifier,
        )),
      );
    }
  }
  $header = array(
    t('Keyword'),
    t('Value'),
  );
  $form['advanced']['contexts']['context'] = array(
    '#markup' => theme('table', array(
      'header' => $header,
      'rows' => $rows,
    )),
  );

  // Store the old cache key so we can look up any rules that needs changing.
  $form['old_cache_key'] = array(
    '#type' => 'value',
    '#value' => $conf['cache_key'],
  );

  // Store the display cache key so we can use it in the submit callback.
  $form['display_cache_key'] = array(
    '#type' => 'value',
    '#value' => $display->cache_key,
  );
  return $form;
}