public static function Botcha::getAdminForm in BOTCHA Spam Prevention 6.2
Same name and namespace in other branches
- 6.3 controller/application/botcha.application.controller.inc \Botcha::getAdminForm()
- 7.2 controller/botcha.controller.inc \Botcha::getAdminForm()
- 7.3 controller/application/botcha.application.controller.inc \Botcha::getAdminForm()
2 calls to Botcha::getAdminForm()
- botcha_forms_form in ./botcha.admin.inc
- Callback for "Forms" admin page.
Configuration of which forms to protect, with what recipe.
- botcha_form_form in ./botcha.admin.inc
- Edit existent or add BOTCHA protection to another form.
File
- controller/botcha.controller.inc, line 33
- Contains Botcha class.
Class
- Botcha
- Singleton realization of botcha application.
Code
public static function getAdminForm($form_name) {
$form = array();
switch ($form_name) {
case 'form_edit':
list($form_name, $form_state, $botcha_form) = func_get_args();
if ($botcha_form instanceof BotchaFormNone) {
drupal_goto(Botcha::BOTCHA_ADMIN_PATH . '/form/add', array(
'query' => array(
'botcha_form_id' => $botcha_form->id,
),
));
}
if ($edit = !empty($botcha_form)) {
$operation = 'edit';
$isEnabled = $botcha_form
->isEnabled();
$recipebook = $botcha_form
->getRecipebook();
$botcha_form_id_default = check_plain($botcha_form->id);
$validate = array();
$button = t('Save');
}
else {
$operation = 'add';
$isEnabled = TRUE;
$recipebook = Botcha::getRecipebook();
$botcha_form_id_default = !empty($_GET['botcha_form_id']) ? $_GET['botcha_form_id'] : NULL;
$validate = array(
'botcha_form_id_validate',
);
$button = t('Add');
}
$form['botcha_operation'] = array(
'#type' => 'value',
'#value' => $operation,
);
$form['botcha_enabled'] = array(
'#type' => 'checkbox',
'#title' => t('Enabled'),
'#description' => t('Enable BOTCHA protection for the form.'),
'#default_value' => $isEnabled,
);
$form['botcha_form_id'] = array(
'#type' => 'textfield',
'#title' => t('Form ID'),
'#description' => t('The Drupal form_id of the form to add the BOTCHA protection to.'),
'#required' => TRUE,
'#disabled' => $edit,
'#maxlength' => 128,
'#element_validate' => $validate,
);
if ($edit) {
$form['botcha_form_id']['#value'] = $botcha_form_id_default;
}
else {
$form['botcha_form_id']['#default_value'] = $botcha_form_id_default;
}
$options = array();
$recipebooks = Botcha::getRecipebooks(TRUE);
foreach ($recipebooks as $rb) {
$options[$rb->id] = $rb->title;
}
$form['botcha_form_recipebook'] = array(
'#type' => 'select',
'#title' => t('Recipe book'),
'#description' => t('Recipe book to apply to the form.'),
'#default_value' => $recipebook->id,
'#options' => $options,
'#disabled' => !$isEnabled,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => $button,
);
break;
case 'form_list':
if (module_exists('captcha')) {
$form['botcha_form_protection']['botcha_on_captcha_forms'] = array(
'#type' => 'checkbox',
'#title' => t('Add BOTCHA to forms selected for CAPTCHA'),
'#default_value' => variable_get('botcha_on_captcha_forms', TRUE),
'#description' => t('This option makes it easy to manage BOTCHA settings on forms. When enabled, all forms that are configured to have CAPTCHA on them (<a href="@captcha">see configuration</a>) will also be selected for BOTCHA protection.!more', array(
'@captcha' => url('admin/user/captcha'),
'!more' => module_exists('captcha') ? '' : '<br />' . t('<b>Note:</b> <a href="@captcha_home">CAPTCHA module</a> is not installed. This setting will have no effect.', array(
'@captcha_home' => 'http://drupal.org/project/captcha',
)),
)),
);
}
$form['botcha_form_protection']['botcha_form_id_overview'] = array(
'#theme' => 'botcha_forms_form_botcha_forms',
'#tree' => TRUE,
);
$form['botcha_form_protection']['botcha_form_id_overview']['#header'] = array(
t('Enabled'),
'form_id',
t('Recipe book'),
);
$form['botcha_form_protection']['botcha_form_id_overview']['botcha_forms'] = array();
$forms = Botcha::getForms(TRUE);
foreach ($forms as $botcha_form) {
$item_form = Botcha::getAdminForm('form_edit', array(), $botcha_form);
unset($item_form['submit']);
unset($item_form['botcha_operation']);
unset($item_form['botcha_enabled']['#title']);
unset($item_form['botcha_enabled']['#description']);
$form['botcha_form_protection']['botcha_form_id_overview']['botcha_forms'][$botcha_form->id] = $item_form;
}
$form['botcha_form_protection']['botcha_administration_mode'] = array(
'#type' => 'checkbox',
'#title' => t('Add BOTCHA administration links to forms'),
'#default_value' => variable_get('botcha_administration_mode', FALSE),
'#description' => t('This option makes it easy to manage BOTCHA settings on forms. When enabled, users with the "%adminbotcha" permission will see a fieldset with BOTCHA administration links on all forms, except on administrative pages.', array(
'%adminbotcha' => t('administer BOTCHA settings'),
)),
);
$form['botcha_form_protection']['botcha_allow_on_admin_pages'] = array(
'#type' => 'checkbox',
'#title' => t('Allow BOTCHAs and BOTCHA administration links on administrative pages'),
'#default_value' => variable_get('botcha_allow_on_admin_pages', FALSE),
'#description' => t('This option makes it possible to add BOTCHAs to forms on administrative pages. BOTCHAs are disabled by default on administrative pages (which shouldn\'t be accessible to untrusted users normally) to avoid the related overhead. In some situations, e.g. in the case of demo sites, it can be usefull to allow BOTCHAs on administrative pages.'),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save configuration'),
);
$form['#theme'] = 'system_settings_form';
break;
}
return $form;
}