You are here

function esi_panels_esi_cache_settings_form in ESI: Edge Side Includes 7.3

Admin-settings form for configuring the ESI cache on panel panes.

1 string reference to 'esi_panels_esi_cache_settings_form'
esi.inc in modules/esi_panels/plugins/cache/esi.inc
ESI cache plugin. Substitutes esi-tags for a panel-pane's content.

File

modules/esi_panels/plugins/cache/esi.inc, line 81
ESI cache plugin. Substitutes esi-tags for a panel-pane's content.

Code

function esi_panels_esi_cache_settings_form($conf, $display, $pid) {

  // Use the TTL from the config if provided, or a suitable default.
  $esi_ttl = isset($conf['esi_ttl']) ? $conf['esi_ttl'] : (int) variable_get('esi_panels_esi_default_ttl', ESI_DEFAULT_TTL);
  $pane = isset($display->content[$pid]) ? $display->content[$pid] : FALSE;

  // Load up the pane information to examine the context.
  $form['esi_ttl'] = array(
    '#title' => t('Cache Maximum Age (TTL)'),
    '#type' => 'select',
    '#options' => esi_max_age_options($esi_ttl),
    '#default_value' => $esi_ttl,
    '#description' => t('External page caches (proxy/browser) will not deliver cached paged older than this setting; time to live in short.'),
  );
  $form['override_context'] = array(
    '#title' => t('Override cache context'),
    '#type' => 'fieldset',
    '#description' => t('The context requested by the pane (and provided by the parent panel) will be used by default to create separate versions of the pane for each context.'),
    '#collapsible' => TRUE,
    '#collapsed' => empty($conf['override_context']['esi_override_context']),
  );

  // Describe the current panels context: placeholder if there is no context.
  $form['override_context']['pane_context'] = array(
    '#type' => 'item',
    '#title' => t('Current panels context'),
    '#prefix' => '<div class="current_context">',
    '#suffix' => '</div>',
    '#markup' => t("This pane doesn't use panels context."),
  );

  // If there is context, add to the placeholder.
  if (!empty($pane->configuration['context'])) {

    // The context is a simple identifier - e.g. "argument_entity_id:node_1".
    // The description of this context - e.g. "Node being viewed" - is
    // generated by the task handler.
    $context_id = $pane->configuration['context'];
    $context = $display->context[$context_id];
    $form['override_context']['pane_context']['#markup'] = t($context->identifier);
  }
  $form['override_context']['esi_override_context'] = array(
    '#title' => t('Override cache context'),
    '#description' => t('Must be selected to enable editing of other options.'),
    '#type' => 'checkbox',
    '#default_value' => !empty($conf['override_context']['esi_override_context']),
  );
  $form['override_context']['esi_overridden_context__pane_context'] = array(
    '#title' => t('Cache per pane-context'),
    '#description' => t("The contents of this pane changes depending on the pane context provided by the panel."),
    '#type' => 'checkbox',
    '#default_value' => !empty($conf['override_context']['esi_overridden_context__pane_context']),
    // If this pane doesn't provide context, this option isn't applicable.
    '#disabled' => empty($pane->configuration['context']),
    '#states' => array(
      'disabled' => array(
        // override_context to take.
        ':input[name="settings[override_context][esi_override_context]"]' => array(
          'unchecked' => TRUE,
        ),
      ),
    ),
  );
  $form['override_context']['esi_overridden_context__page'] = array(
    '#title' => t('Cache per page'),
    '#description' => t("The contents of this pane changes depending on the page on which it's displayed."),
    '#type' => 'checkbox',
    '#default_value' => !empty($conf['override_context']['esi_overridden_context__page']),
    '#states' => array(
      'disabled' => array(
        // override_context to take.
        ':input[name="settings[override_context][esi_override_context]"]' => array(
          'unchecked' => TRUE,
        ),
      ),
    ),
  );
  $form['override_context']['esi_overridden_context__user'] = array(
    '#title' => t('User context'),
    '#description' => t("How a user or their roles affect the pane."),
    '#type' => 'radios',
    '#options' => array(
      DRUPAL_CACHE_GLOBAL => t('Pane is shared by all users'),
      DRUPAL_CACHE_PER_ROLE => t("Pane changes according to the current user's roles"),
      DRUPAL_CACHE_PER_USER => 'Pane changes according to the current user',
      ESI_PANELS_CACHE_AUTHENTICATED => 'Pane changes depending on whether the user is anonymous or authenticated',
    ),
    '#default_value' => isset($conf['override_context']['esi_overridden_context__user']) ? $conf['override_context']['esi_overridden_context__user'] : DRUPAL_CACHE_PER_ROLE,
    '#states' => array(
      'disabled' => array(
        // override_context to take.
        ':input[name="settings[override_context][esi_override_context]"]' => array(
          'unchecked' => TRUE,
        ),
      ),
    ),
  );
  return $form;
}