public function Botcha::submitAdminForm in BOTCHA Spam Prevention 7.3
Same name and namespace in other branches
- 6.2 controller/botcha.controller.inc \Botcha::submitAdminForm()
- 6.3 controller/application/botcha.application.controller.inc \Botcha::submitAdminForm()
- 7.2 controller/botcha.controller.inc \Botcha::submitAdminForm()
Unified submit handler for admin forms.
File
- controller/
application/ botcha.application.controller.inc, line 821 - Contains Botcha class.
Class
- Botcha
- Just a middleman for achieving purposes such as:
Code
public function submitAdminForm($form, &$form_state) {
parent::submitAdminForm($form, $form_state);
$form_name = $form['#form_name']['#value'];
switch ($form_name) {
// @todo Refactor switch stuff with classes since they are similar a lot.
case 'general':
// Generate the secret key.
// @todo Move secret key generation to validate phase.
if (empty($form_state['values']['botcha_secret'])) {
// Generate unique secret for this site
$secret = $this
->generateSecretKey();
$form_state['values']['botcha_secret'] = $secret;
drupal_set_message(t('New BOTCHA secret key have been generated.'));
}
// Do what system_settings_form() would do with regular variable fields
variable_set('botcha_secret', $form_state['values']['botcha_secret']);
variable_set('botcha_loglevel', $form_state['values']['botcha_loglevel']);
drupal_set_message(t('The BOTCHA settings were saved.'), 'status');
break;
case 'form_delete':
$form_id = $form_state['values']['botcha_form_id'];
$form_controller = $this
->getController(Botcha::CONTROLLER_TYPE_FORM);
$botcha_form = $form_controller
->getForm($form_id, FALSE);
$form_controller
->delete($botcha_form);
drupal_set_message(t('Deleted BOTCHA protection for form %form_id.', array(
'%form_id' => $form_id,
)));
$form_state['redirect'] = Botcha::ADMIN_PATH . '/form';
break;
case 'form_edit':
$form_id = $form_state['values']['botcha_form_id'];
$enabled = $form_state['values']['botcha_enabled'];
$rbid = $form_state['values']['botcha_form_recipebook'];
$operation = $form_state['values']['botcha_operation'];
$add = $operation == 'add';
$form_controller = $this
->getController(Botcha::CONTROLLER_TYPE_FORM);
$botcha_form = $form_controller
->getForm($form_id, $add)
->setEnabled($enabled)
->setRecipebook($rbid);
$form_controller
->save($botcha_form);
switch ($operation) {
case 'edit':
// Check if the form was really modified.
// @todo Refactor in a more general manner.
$edited = $form['botcha_enabled']['#default_value'] != $form['botcha_enabled']['#value'] || $form['botcha_form_recipebook']['#default_value'] != $form['botcha_form_recipebook']['#value'];
if ($edited) {
drupal_set_message(t('Saved BOTCHA form settings for %form_id.', array(
'%form_id' => $form_id,
)), 'status');
}
break;
case 'add':
default:
// Check if the form was really modified.
// @todo Refactor in a more general manner.
$added = $form['botcha_form_id']['#default_value'] != $form['botcha_form_id']['#value'] || $form['botcha_form_recipebook']['#default_value'] != $form['botcha_form_id']['#value'];
if ($added) {
drupal_set_message(t('Added BOTCHA form %form_id.', array(
'%form_id' => $form_id,
)), 'status');
}
break;
}
$form_state['redirect'] = Botcha::ADMIN_PATH . '/form';
break;
case 'form_list':
$forms = $form['botcha_form_protection']['botcha_form_id_overview']['botcha_forms'];
$form_ids = element_children($forms);
foreach ($form_ids as $form_id) {
// @todo Replace this workaround with more beautiful solution.
$fake_form_state['values'] = array(
'botcha_form_id' => $form_state['values']['botcha_form_id_overview']['botcha_forms'][$form_id]['botcha_form_id'],
'botcha_enabled' => $form_state['values']['botcha_form_id_overview']['botcha_forms'][$form_id]['botcha_enabled'],
'botcha_form_recipebook' => $form_state['values']['botcha_form_id_overview']['botcha_forms'][$form_id]['botcha_form_recipebook'],
'botcha_operation' => 'edit',
);
$this
->submitAdminForm($forms[$form_id], $fake_form_state);
}
// Do what system_settings_form() would do with regular variable fields
variable_set('botcha_on_captcha_forms', !empty($form_state['values']['botcha_on_captcha_forms']) ? $form_state['values']['botcha_on_captcha_forms'] : FALSE);
variable_set('botcha_administration_mode', $form_state['values']['botcha_administration_mode']);
variable_set('botcha_allow_on_admin_pages', $form_state['values']['botcha_allow_on_admin_pages']);
drupal_set_message(t('The BOTCHA settings were saved.'), 'status');
break;
case 'recipe_delete':
// Unused yet.
break;
case 'recipe_edit':
// Unused yet.
break;
case 'recipe_list':
break;
case 'recipebook_delete':
$form_state['redirect'] = Botcha::ADMIN_PATH . '/recipebook';
// Remove recipe book.
$this
->getController(Botcha::CONTROLLER_TYPE_RECIPEBOOK)
->delete($form['#botcha_recipebook']);
break;
case 'recipebook_edit':
$values = $form_state['values'];
$recipebook_controller = $this
->getController(Botcha::CONTROLLER_TYPE_RECIPEBOOK);
$recipebook = $recipebook_controller
->getRecipebook($values['id'])
->setTitle($values['title'])
->setDescription($values['description']);
foreach ($values['recipes'] as $recipe_id => $value) {
if ($value) {
$recipebook
->setRecipe($recipe_id);
}
else {
$recipebook
->unsetRecipe($recipe_id);
}
}
$recipebook_controller
->save($recipebook);
$form_state['redirect'] = Botcha::ADMIN_PATH . '/recipebook';
drupal_set_message(t('Settings for recipe book "%recipebook" are successfully saved.', array(
'%recipebook' => $recipebook->id,
)), 'status');
break;
case 'recipebook_list':
break;
}
}