function galleria_form_optionset_edit_submit_add in Galleria 7
Submit handler for 'Add option' button; Add a new option to the set.
1 string reference to 'galleria_form_optionset_edit_submit_add'
- galleria_form_optionset_edit in includes/
galleria.admin.inc - Form builder; Form to edit a given option set.
File
- includes/
galleria.admin.inc, line 772 - Administrative page callbacks for the galleria module.
Code
function galleria_form_optionset_edit_submit_add($form, &$form_state) {
$optionset =& $form_state['optionset'];
// $optionset->options = array_fill_keys(array_keys(galleria_option_elements()), NULL);
if (!empty($form_state['values']['new_option'])) {
$new_option_element = 'new_option';
}
elseif (!empty($form_state['values']['new_option_custom'])) {
$new_option_element = 'new_option_custom';
}
if (isset($new_option_element)) {
$new_option = $form_state['values'][$new_option_element];
if (!array_key_exists($new_option, $optionset->options)) {
// Add the new option with a NULL value. The input element cares for a default value.
$optionset->options[$new_option] = NULL;
// Reset the input field
$form_state['input'][$new_option_element] = '';
drupal_set_message(t('Option %name added.', array(
'%name' => $new_option,
)));
}
else {
form_set_error($new_option_element, t('This set already includes the %name option.', array(
'%name' => $new_option,
)));
}
}
$form_state['rebuild'] = TRUE;
}