public static function Botcha::getAdminForm in BOTCHA Spam Prevention 7.2
Same name and namespace in other branches
- 6.2 controller/botcha.controller.inc \Botcha::getAdminForm()
- 6.3 controller/application/botcha.application.controller.inc \Botcha::getAdminForm()
- 7.3 controller/application/botcha.application.controller.inc \Botcha::getAdminForm()
Get admin form.
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 35 - 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();
// Determine default values depending on whether we add or edit form.
$edit = !empty($botcha_form);
if ($edit) {
if ($botcha_form instanceof BotchaFormNone) {
drupal_goto(Botcha::BOTCHA_ADMIN_PATH . '/form/add', array(
'query' => array(
'botcha_form_id' => $botcha_form->id,
),
));
}
$operation = 'edit';
$isEnabled = $botcha_form
->isEnabled();
$recipebook = $botcha_form
->getRecipebook();
$botcha_form_id_default = check_plain($botcha_form->id);
$button = t('Save');
}
else {
$operation = 'add';
$isEnabled = TRUE;
// 'default' will be selected.
$recipebook = Botcha::getRecipebook();
$query_params = drupal_get_query_parameters();
$botcha_form_id_default = !empty($query_params['botcha_form_id']) ? $query_params['botcha_form_id'] : NULL;
$button = t('Add');
}
// Insert a field that allows to understand whether it is creation or edition form submission.
$form['botcha_operation'] = array(
'#type' => 'value',
'#value' => $operation,
);
// Determine whether the form enabled or not.
$form['botcha_enabled'] = array(
'#type' => 'checkbox',
'#title' => t('Enabled'),
'#description' => t('Enable BOTCHA protection for the form.'),
'#default_value' => $isEnabled,
);
// Use passed as a parameter form id.
$form['botcha_form_id'] = array(
'#type' => 'machine_name',
'#title' => t('Form ID'),
'#description' => t('The Drupal form_id of the form to add the BOTCHA protection to.'),
'#default_value' => $botcha_form_id_default,
'#disabled' => $edit,
'#maxlength' => 128,
'#machine_name' => array(
'exists' => 'botcha_form_exists',
),
);
$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,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => $button,
);
break;
case 'form_list':
if (module_exists('captcha')) {
// Checkbox to put BOTCHA on same forms as 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/config/people/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',
)),
)),
);
}
// List known form_ids.
$form['botcha_form_protection']['botcha_form_id_overview'] = array(
'#theme' => 'botcha_forms_form_botcha_forms',
'#tree' => TRUE,
);
// @todo Remove it.
//$form['botcha_form_protection']['botcha_form_id_overview']['#header'] = array('form_id', t('Recipe book'), t('Operations'));
$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) {
// Get individual admin form as a row of our overview table.
$item_form = Botcha::getAdminForm('form_edit', array(), $botcha_form);
// Remove submit button ...
unset($item_form['submit']);
// ... and botcha_operation field ...
unset($item_form['botcha_operation']);
// ... and also additional properties of some fields.
unset($item_form['botcha_enabled']['#title']);
unset($item_form['botcha_enabled']['#description']);
/* @todo Remove it.
foreach (element_children($item_form) as $column) {
// Workaround for machine_name which is impossible to leave without
// title and description, because it fills them with defaults.
$item_form[$column]['#title'] = ' ';
$item_form[$column]['#description'] = ' ';
}
*
*/
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;
/* @todo Remove it.
$form['botcha_form_protection']['botcha_form_id_overview']['botcha_forms'][$botcha_form->id] = array();
$form['botcha_form_protection']['botcha_form_id_overview']['botcha_forms'][$botcha_form->id]['form_id'] = array(
'#markup' => $botcha_form->id,
);
// Recipe book, enabled for this form.
$recipebook = $botcha_form->getRecipebook();
$form['botcha_form_protection']['botcha_form_id_overview']['botcha_forms'][$botcha_form->id]['recipebook'] = array(
// @todo Remove hardcode.
// @todo Abstract it.
//'#value' => ...,
'#markup' => ($recipebook instanceof BotchaRecipebookNone || $recipebook->id == 'forbidden_forms')
? $recipebook->id
: l($recipebook->id, Botcha::BOTCHA_ADMIN_PATH . "/recipebook/{$recipebook->id}"),
);
// Additional operations.
$form['botcha_form_protection']['botcha_form_id_overview']['botcha_forms'][$botcha_form->id]['operations'] = array(
'#markup' => ($recipebook->id == 'forbidden_forms')
? ''
: implode(" | ", array(
l(t('Edit'), Botcha::BOTCHA_ADMIN_PATH . "/form/{$botcha_form->id}"),
l(t('Disable'), Botcha::BOTCHA_ADMIN_PATH . "/form/{$botcha_form->id}/delete"),
)),
);
*
*/
}
// Field for the BOTCHA administration mode.
$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'),
)),
);
// Field for the BOTCHAs on admin pages.
$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['buttons']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save configuration'),
);
$form['#theme'] = 'system_settings_form';
break;
}
return $form;
}