function purge_item_add_form in Purge 7.2
Menu callback for the add item form.
1 string reference to 'purge_item_add_form'
- purge_menu in ./
purge_ui.module - Implements hook_menu().
File
- includes/
purge_ui.inc, line 45 - Provides administrative interface for the Purge module.
Code
function purge_item_add_form($form, &$form_state, $item_type) {
// Load the bundle.
$bundle = purge_get_bundle_ui($form, $form_state, 'add', $item_type);
// And load the example bundle.
module_load_include('inc', 'purge', 'includes/defaults');
$example_bundle = new PurgePurgerBundleExample();
$form = array();
// Hidden field with item_type information for later processing.
$form['item_type'] = array(
'#type' => 'hidden',
'#default_value' => $item_type,
);
// First check if this itme type is allowed to be added.
if (!in_array(PURGE_ACCESS_FULL, $bundle->type[$item_type]->access)) {
drupal_set_message(t('You are not permitted to add items of type @type.', array(
'@type' => $bundle->type[$item_type]->name,
)));
drupal_goto('admin/config/system/purge');
return;
}
// The header of the selecfield.
$header = array(
'name' => t('Name'),
'description' => t('Description'),
'provider' => t('Provided by'),
);
// The options.
// First the option to create a new item.
$options = array(
'new' => array(
'name' => t('New'),
'description' => t('Start from scratch with an empty @type.', array(
'@type' => $bundle->type[$item_type]->name,
)),
'provider' => t('You!'),
),
);
// Now include all built in examples.
foreach ($example_bundle->{$item_type} as $item_name => $item) {
$options[$item_name] = array(
'name' => $item->name,
'description' => $item->description,
'provider' => t('Purge Examples'),
);
}
$form['template_select'] = array(
'#type' => 'tableselect',
'#header' => $header,
'#options' => $options,
'#multiple' => FALSE,
'#default_value' => 'new',
);
// Submit
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Select'),
);
return $form;
}