You are here

function flush_page_cache_admin_settings in Flush page cache 6

Same name and namespace in other branches
  1. 7 flush_page_cache.admin.inc \flush_page_cache_admin_settings()

Form builder; Administration page for the 'Flush page cache' module.

1 string reference to 'flush_page_cache_admin_settings'
flush_page_cache_menu in ./flush_page_cache.module
Implementation of hook_menu().

File

./flush_page_cache.admin.inc, line 20
Administration pages for the 'Flush page cache' module.

Code

function flush_page_cache_admin_settings($form_state = NULL) {

  // Link settings
  $form['link'] = array(
    '#type' => 'fieldset',
    '#title' => t('Link settings'),
  );
  $form['link']['flush_page_cache_footer_link'] = array(
    '#type' => 'checkbox',
    '#title' => t('Add flush page cache link to footer'),
    '#default_value' => variable_get('flush_page_cache_footer_link', module_exists('admin_menu') ? '0' : '1'),
  );

  // Custom settings
  $form['flush_page_cache_custom'] = array(
    '#tree' => TRUE,
    '#type' => 'fieldset',
    '#title' => t('Custom settings'),
    '#description' => t('Enter custom cache objects to be purged when a page\'s cache is flushed, using the <a href="@href">cache_clear_all()</a> function.', array(
      '@href' => 'http://api.drupal.org/api/drupal/includes!cache.inc/function/cache_clear_all/6',
    )) . '<ul>' . '<li>' . t("<b>Path</b>: The path on which this cache entry should be cleared. The '*' character is a wildcard. Example paths are %blog for the blog page and %blog-wildcard for every personal blog. %front is the front page.", array(
      '%blog' => 'blog',
      '%blog-wildcard' => 'blog/*',
      '%front' => '<front>',
    )) . '</li>' . '<li>' . t('<b>Cache ID ($cid)</b>: The cache ID to delete. If left blank, all cache entries that can expire are deleted.') . '</li>' . '<li>' . t('<b>Table ($table)</b>: The table $table to delete from.') . '</li>' . '<li>' . t('<b>Wildcard ($wildcard)</b>: If $wildcard is TRUE, cache IDs starting with $cid are deleted in addition to the exact cache ID specified by $cid. If $wildcard is TRUE and $cid is \'*\' then the entire table $table is emptied.') . '</li>' . '</ul>',
  );

  // Build custom settings from post back or variables.
  if (!empty($form_state['post']['flush_page_cache_custom'])) {
    $custom = flush_page_cache_custom_build($form_state['post']);
  }
  else {
    $custom = variable_get('flush_page_cache_custom', array(
      array(
        '*',
        'variables',
        'cache',
        FALSE,
      ),
    ));
  }
  $form['flush_page_cache_custom']['settings_table'] = array(
    '#theme' => 'flush_page_cache_custom_settings_table',
    '#prefix' => '<div id="flush-page-cache-custom-settings-table">',
    '#suffix' => '</div>',
  );
  $delta = 0;
  foreach ($custom as $item) {
    $form['flush_page_cache_custom']['settings_table'][$delta] = flush_page_cache_custom_settings_row($delta, $item[0], $item[1], $item[2], $item[3]);
    $delta++;
  }

  // Add placeholder rows
  if (isset($form_state['post']['flush_page_cache_custom']['settings_table'])) {
    $number_of_empty_rows = count($form_state['post']['flush_page_cache_custom']['settings_table']) - count($custom);
    if (isset($form_state['post']['op']) && $form_state['post']['op'] == t('Add rows')) {
      $number_of_empty_rows += 3;

      // Add 3 new rows.
    }
    elseif ($number_of_empty_rows != 1) {
      $number_of_empty_rows -= 1;

      // Minus 1 from remove request.
    }
  }
  else {
    $number_of_empty_rows = 3;

    // Alway include 3 new rows.
  }
  for ($index = 0; $index < $number_of_empty_rows; $index++) {
    $form['flush_page_cache_custom']['settings_table'][$delta] = flush_page_cache_custom_settings_row($delta);
    $delta++;
  }
  $form['flush_page_cache_custom']['add'] = array(
    '#type' => 'button',
    '#value' => t('Add rows'),
    '#ahah' => array(
      'path' => 'admin/settings/flush_page_cache/js',
      'wrapper' => 'flush-page-cache-custom-settings-table',
      'method' => 'replace',
      'effect' => 'fade',
    ),
  );
  $form['buttons']['save'] = array(
    '#type' => 'submit',
    '#value' => t('Save configuration'),
  );
  return $form;
}