function galleria_form_optionset_edit in Galleria 7
Form builder; Form to edit a given option set.
1 string reference to 'galleria_form_optionset_edit'
- galleria_menu in ./
galleria.module - Implements hook_menu().
File
- includes/
galleria.admin.inc, line 529 - Administrative page callbacks for the galleria module.
Code
function galleria_form_optionset_edit($form, &$form_state, $optionset) {
if (empty($form_state['optionset'])) {
$form_state['optionset'] = $optionset;
}
else {
$optionset = $form_state['optionset'];
}
// Print a warning if there's no height and/or width option in the set.
foreach (array(
'height',
'width',
) as $dimension) {
if (!array_key_exists($dimension, $optionset->options)) {
drupal_set_message(t('You should add a %dimension option if you don\'t plan to set it manually via CSS.', array(
'%dimension' => $dimension,
)), 'warning');
}
}
// Title
$form['title'] = array(
'#type' => 'textfield',
'#maxlength' => '255',
'#title' => t('Title'),
'#default_value' => $optionset->title,
'#description' => t('A human-readable title for this option set.'),
'#required' => TRUE,
);
// Show the theme select box if there is more than one theme
$themes = array_keys(galleria_get_themes(TRUE));
if (count($themes) == 1) {
$form['theme'] = array(
'#type' => 'hidden',
'#value' => $themes[0],
);
}
elseif (count($themes) > 1) {
asort($themes);
$form['theme'] = array(
'#type' => 'select',
'#title' => t('Theme'),
'#description' => t('As you have more than one Galleria theme installed, please select the one to use.'),
'#options' => array_combine($themes, $themes),
'#default_value' => $optionset->theme,
);
}
// Show multi-select field for plugins
$plugins = array_keys(galleria_get_plugins(TRUE));
asort($plugins);
$form['plugins'] = array(
'#type' => 'select',
'#multiple' => TRUE,
'#title' => t('Plugins'),
'#description' => t('Please select a subset of plugins to enable for this specific optionset. You may select multiple by holding down the Cmd/Ctrl or Shift key while clicking.'),
'#options' => array_combine($plugins, $plugins),
'#default_value' => $optionset->plugins,
);
// Show select boxes for the various image styles (thumbnail, normal, big)
$image_styles = image_style_options(FALSE);
$form['image_styles'] = array(
'#type' => 'fieldset',
'#title' => 'Image styles',
'#tree' => TRUE,
);
$form['image_styles']['thumb'] = array(
'#type' => 'select',
'#title' => t('Thumbnail image style'),
'#description' => t('Image style for the thumbnail bar.'),
'#empty_option' => t('None (original image)'),
'#options' => $image_styles,
'#default_value' => $optionset->imagestyle_thumb,
);
$form['image_styles']['normal'] = array(
'#type' => 'select',
'#title' => t('Normal image style'),
'#description' => t('Image style for the main stage images.'),
'#empty_option' => t('None (original image)'),
'#options' => $image_styles,
'#default_value' => $optionset->imagestyle_normal,
);
$form['image_styles']['big'] = array(
'#type' => 'select',
'#title' => t('Big image style'),
'#description' => t('Image style for lightbox or fullscreen theme.'),
'#empty_option' => t('None (original image)'),
'#options' => $image_styles,
'#default_value' => $optionset->imagestyle_big,
);
// Option table
$form['options'] = array(
'#theme' => 'galleria_form_table',
'#tree' => TRUE,
'#header' => array(
t('Name'),
t('Value'),
t('Operations'),
),
);
$i = 0;
foreach ($optionset->options as $key => $value) {
$option_element = galleria_option_element($key, $value);
$form['options'][] = array(
'name' => array(
'#type' => 'item',
'#title' => check_plain($key),
'#description' => isset($option_element['#title']) ? $option_element['#title'] : '',
),
'value' => $option_element + array(
'#option_name' => $key,
'#title_display' => 'none',
),
'delete' => array(
'#type' => 'submit',
'#name' => 'button_del_' . $i++,
'#value' => t('Delete'),
'#submit' => array(
'galleria_form_optionset_edit_submit_delete',
),
'#limit_validation_errors' => array(),
),
);
}
// 'Add option' row at the end of the table
$options = array_diff(array_keys(galleria_option_elements()), array_keys($optionset->options));
$options = empty($options) ? array() : array_combine($options, $options);
$form['options'][] = array(
'add_option_row' => array(
'#table_attributes' => array(
'colspan' => '3',
'class' => array(
'container-inline',
),
),
'#tree' => FALSE,
'new_option' => array(
'#type' => 'select',
'#options' => $options,
'#empty_option' => t('Select or enter:'),
),
'new_option_custom' => array(
'#type' => 'textfield',
'#states' => array(
'visible' => array(
':input[name="new_option"]' => array(
'value' => '',
),
),
),
),
'button_add' => array(
'#type' => 'submit',
'#name' => 'add_option',
'#value' => t('Add option'),
'#submit' => array(
'galleria_form_optionset_edit_submit_add',
),
'#limit_validation_errors' => array(
array(
'new_option',
),
array(
'new_option_custom',
),
),
),
),
);
$form['actions'] = array(
'#type' => 'actions',
'submit' => array(
'#type' => 'submit',
'#name' => 'submit',
'#value' => t('Save option set'),
),
'cancel' => array(
'#type' => 'link',
'#title' => t('Cancel'),
'#href' => 'admin/config/media/galleria',
),
);
return $form;
}