You are here

function panels_content_cache_settings_form in Panels Content Cache 7

Same name and namespace in other branches
  1. 6 plugins/cache/content.inc \panels_content_cache_settings_form()
1 string reference to 'panels_content_cache_settings_form'
content.inc in plugins/cache/content.inc
Provides a content-based caching option for panel panes.

File

plugins/cache/content.inc, line 297
Provides a content-based caching option for panel panes.

Code

function panels_content_cache_settings_form($conf, $display, $pid) {
  ctools_include('dependent');
  $options = array(
    'none' => 'none',
  ) + drupal_map_assoc(array(
    15,
    30,
    60,
    120,
    180,
    240,
    300,
    600,
    900,
    1200,
    1800,
    3600,
    7200,
    14400,
    28800,
    43200,
    86400,
    172800,
    259200,
    345600,
    604800,
  ), 'format_interval');
  $form['lifetime'] = array(
    '#title' => t('Lifetime'),
    '#type' => 'select',
    '#options' => $options,
    '#default_value' => isset($conf['lifetime']) ? $conf['lifetime'] : 'none',
    '#description' => t('The cache lifetime is the minimum amount of time that will elapse before the cache is emptied and recreated. If set to none the cache will not be recreated unless a content update triggers a rebuild.'),
  );
  $form['content_types'] = array(
    '#title' => t('Node types'),
    '#description' => t('Checks for new or updated nodes of any of the selected types.'),
    '#type' => 'checkboxes',
    '#options' => node_type_get_names(),
    '#default_value' => isset($conf['content_types']) ? $conf['content_types'] : array(),
    '#required' => TRUE,
  );
  if (!isset($conf['granularity'])) {
    $conf['granularity'] = array();
  }
  elseif (!is_array($conf['granularity'])) {
    $conf['granularity'] = array(
      $conf['granularity'] => $conf['granularity'],
    );
  }
  $form['granularity'] = array(
    '#title' => t('Granularity'),
    '#type' => 'checkboxes',
    '#options' => array(
      'url' => t('Current URL'),
      'args' => t('Arguments'),
      'context' => t('Context'),
      'user' => t('Active User'),
      'user_role' => t("Active user's role(s)"),
    ),
    '#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['granularity_url'] = array(
    '#type' => 'radios',
    '#title' => t('Which format should the URL use?'),
    '#options' => array(
      // Example: 'http://example.com/site',
      // How to generate: $GLOBALS['base_url'] . base_path()
      'base_url' => t('Absolute base URL: %url', array(
        '%url' => $GLOBALS['base_url'] . base_path(),
      )),
      // Example: 'http://example.com/site/node/123',
      // How to generate: $GLOBALS['base_url'] . base_path() . current_path()
      'base_url_system' => t('Absolute system URL: %url', array(
        '%url' => $GLOBALS['base_url'] . base_path() . 'node/123',
      )),
      // Example: 'http://example.com/site/page/alias',
      // How to generate: $GLOBALS['base_url'] . base_path() . request_path()
      'base_url_alias' => t('Absolute URL alias: %url', array(
        '%url' => $GLOBALS['base_url'] . base_path() . 'page/alias',
      )),
      // Example: '/site/',
      // How to generate: base_path()
      'base_path' => t('Relative base URL: %url', array(
        '%url' => base_path(),
      )),
      // Example: '/site/node/123',
      // How to generate: base_path() . current_path()
      'base_path_system' => t('Relative system URL: %url', array(
        '%url' => base_path() . 'node/123',
      )),
      // Example: '/site/page/alias',
      // How to generate: base_path() . request_path()
      'base_path_alias' => t('Relative URL alias: %url', array(
        '%url' => base_path() . 'page/alias',
      )),
    ),
    '#default_value' => !empty($conf['granularity_base_url']) ? $conf['granularity_base_url'] : 'base_url_system',
    '#description' => t('&bull; The correct prefix of "http://" or "https://" will be used automatically.<br />&bull; If the page does not have an alias, the system URL will be used.'),
    '#dependency' => array(
      'edit-settings-granularity-url' => array(
        1,
      ),
    ),
  );
  $form['granularity_url_query'] = array(
    '#type' => 'checkbox',
    '#title' => t('Include full query string?'),
    '#default_value' => !empty($conf['granularity_url_query']) ? $conf['granularity_url_query'] : FALSE,
    // '#description' => t(''),
    '#dependency' => array(
      'edit-settings-granularity-url' => array(
        1,
      ),
    ),
  );
  $roles = user_roles(TRUE);
  $roles[DRUPAL_AUTHENTICATED_RID] .= ' ' . t('(all logged in users with no additional roles)');
  $form['granularity_roles_as_anon'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Treat users with these role(s) as anonymous'),
    '#options' => $roles,
    '#default_value' => !empty($conf['granularity_roles_as_anon']) ? $conf['granularity_roles_as_anon'] : array(),
    '#description' => t("If the user is logged in and has one of these roles, cache the pane as if the user is anonymous. The 'authenticated user' role is only used if the user does not have any other role."),
    '#dependency' => array(
      'edit-settings-granularity-user-role' => array(
        1,
      ),
    ),
  );
  $form['granularity_role_selection'] = array(
    '#type' => 'radios',
    '#title' => t('How to handle multiple roles:'),
    '#options' => array(
      'all' => t('Use all matching roles; this can lead to a huge number of cache objects due to the possible combinations of roles.'),
      'first' => t('Only use first matching role; useful when roles decrease in permissiveness, e.g. Admin, Editor, Author.'),
      'last' => t('Only use last matching role; useful when roles increase in permissiveness, e.g. Author, Editor, Admin.'),
    ),
    '#default_value' => !empty($conf['granularity_role_selection']) ? $conf['granularity_role_selection'] : 'all',
    '#description' => t('If the user has more than one role, control how the additional roles are considered. This selection does not take into consideration the automatic "authenticated user" role.'),
    '#dependency' => array(
      'edit-settings-granularity-user-role' => array(
        1,
      ),
    ),
  );

  // Add support for the Domain Access module.
  if (module_exists('domain')) {
    $form['granularity']['#options']['domain'] = t('Current domain (Domain Access)');
  }
  return $form;
}