function cacheflush_preset_form in CacheFlush 7
Same name and namespace in other branches
- 7.2 cacheflush.preset.inc \cacheflush_preset_form()
Callback function after drupal_get_form().
Parameters
int $preset_id: Preset id
Return value
array Array with form elements.
3 string references to 'cacheflush_preset_form'
- cacheflush_advanced_form_alter in cacheflush_advanced/
cacheflush_advanced.module - Implements hook_form_alter().
- cacheflush_cron_form_alter in cacheflush_cron/
cacheflush_cron.module - Implements hook_form_alter().
- cacheflush_menu in ./
cacheflush.module - Implements hook_menu().
File
- ./
cacheflush.preset.inc, line 17 - Cacheflush module add/edit form for presets.
Code
function cacheflush_preset_form($form, &$form_state, $preset_id) {
// Getting cache table list.
$form_state['cacheflush_table_list'] = $cache_tables = _cacheflush_get_table_list();
// Getting cache preset list.
$form_state['cacheflush_preset_list'] = $cache_presets = variable_get('cacheflush_preset_list', array());
// Is edit or add.
$form_state['cacheflush_preset_is_edit'] = $preset_id ? TRUE : FALSE;
// Checking if preset id is valid or is a predefined preset.
if ($preset_id && (!isset($cache_presets[$preset_id]) || $preset_id < 5)) {
drupal_set_message(t('Wrong preset id.'), 'error');
return $form;
}
elseif (!$form_state['cacheflush_preset_is_edit']) {
$preset_id = max(array_keys($cache_presets)) + 1;
}
$form_state['cacheflush_preset_id'] = $preset_id;
// Form element for preset name.
$form['cacheflush_preset_name'] = array(
'#type' => "textfield",
'#title' => t('Preset Name'),
'#default_value' => $form_state['cacheflush_preset_is_edit'] ? $cache_presets[$preset_id]['#name'] : '',
'#weight' => 0,
'#required' => TRUE,
);
// Form element, vertical tab parent.
$form['cacheflush_vertical_tabs'] = array(
'#type' => 'vertical_tabs',
'#weight' => 50,
'#attached' => array(
'js' => array(
'vertical-tabs' => drupal_get_path('module', 'cacheflush') . '/js/cacheflush_vertical_tabs.js',
),
),
);
// Vertical tabs.
$form_state['cacheflush_vertical_tabs'] = array(
'vertical_tabs_core' => t('Core cache tables'),
'vertical_tabs_functions' => t('Other core cache options'),
'vertical_tabs_custom' => t('Contrib cache tables'),
'vertical_tabs_often' => t('Other contrib cache options'),
);
// Creating vertical tabs.
$i = 0;
foreach ($form_state['cacheflush_vertical_tabs'] as $key => $value) {
$form[$key] = array(
'#type' => 'fieldset',
'#title' => check_plain($value),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#group' => 'cacheflush_vertical_tabs',
'#tree' => TRUE,
'#weight' => $i++,
);
}
// Adding table elemnts to tabs.
foreach ($cache_tables as $key => $value) {
// Special tab element added only if there module are instaled.
if ($value['category'] == 'often' && !module_exists($key)) {
continue;
}
$form['vertical_tabs_' . $value['category']]["cacheflush_checkbox_{$key}"] = array(
'#type' => "checkbox",
'#title' => check_plain($key),
'#default_value' => isset($cache_presets[$preset_id]['#cacheflush_preset_values'][$key]) ? 1 : 0,
'#description' => check_plain($value['description']),
);
unset($cache_presets[$preset_id]['#cacheflush_preset_values'][$key]);
}
// Form element Submit button.
$form['actions'] = array(
'#type' => 'actions',
);
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Create'),
);
// If editing preset change Submit button name and add Delete button.
if ($form_state['cacheflush_preset_is_edit']) {
$form['actions']['submit']['#value'] = t('Update');
$form['actions']['delete'] = array(
'#type' => 'submit',
'#value' => t('Delete'),
'#submit' => array(
'cacheflush_delete_preset_submit',
),
);
}
// Form element Cancel button.
$form['actions']['cancel'] = array(
'#markup' => l(t('Cancel'), 'admin/config/development/cacheflush'),
);
_cacheflush_form_descriptions($form);
return $form;
}