function galleria_field_formatter_settings_form in Galleria 7
Implements hook_field_formatter_settings_form().
Provides display settings form within the manage display page of an image field with formatter galleria.
File
- ./
galleria.module, line 361 - A light-weight, customizable image gallery plugin for Drupal based on jQuery
Code
function galleria_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) {
$display = $instance['display'][$view_mode];
$settings = $display['settings'];
$form = array(
'#tree' => TRUE,
);
// Show select box for the option set
$optionsets = array();
foreach (galleria_optionsets_load_all() as $name => $optionset) {
$optionsets[$name] = check_plain($optionset->title);
}
$form['optionset'] = array(
'#title' => t('Option set'),
'#type' => 'select',
'#options' => $optionsets,
'#default_value' => $settings['optionset'],
);
if ($field['type'] == 'file') {
// Provide alternate settings to allow selection of caption and alt tags.
$bundles = field_info_instances('file');
// Determine if there are additional fields on the image instance.
if (isset($bundles['image']) && !empty($bundles['image'])) {
$options = array(
'' => t('None'),
);
foreach ($bundles['image'] as $field_name => $field_details) {
$options[$field_name] = $field_details['label'];
}
$form['alt_field'] = array(
'#title' => t('Alt field'),
'#description' => t('Select an optional field to draw alt tags from.'),
'#type' => 'select',
'#options' => $options,
'#default_value' => isset($settings['alt_field']) ? $settings['alt_field'] : '',
);
$form['title_field'] = array(
'#description' => t('Select an optional field to draw images titles from.'),
'#title' => t('Title field'),
'#type' => 'select',
'#options' => $options,
'#default_value' => isset($settings['title_field']) ? $settings['title_field'] : '',
);
}
}
// Show select box for image fields if we're formatting a node_reference field
if ($field['type'] == 'node_reference') {
// Find all image fields
$referenceable_types = array_filter($field['settings']['referenceable_types']);
foreach ($referenceable_types as $referenceable_type) {
$image_fields = array();
foreach (field_info_instances('node', $referenceable_type) as $field_name => $field_instance) {
$field = field_info_field($field_name);
if ($field['type'] == 'image' || $field['type'] == 'media') {
$image_fields[$field_name] = $field_instance['label'];
}
}
if (!empty($image_fields)) {
$form['referenced_fields'][$referenceable_type] = array(
'#type' => 'checkboxes',
'#title' => node_type_get_name($referenceable_type),
'#options' => $image_fields,
'#default_value' => isset($settings['referenced_fields'][$referenceable_type]) ? $settings['referenced_fields'][$referenceable_type] : array(),
);
}
}
if (count($form['referenced_fields']) == 0) {
drupal_set_message(t('The referenced node type(s) does not contain any valid image fields.'), 'error');
}
else {
$form['referenced_fields'] += array(
'#type' => 'fieldset',
'#title' => t('Image source fields'),
'#description' => t('Select the image fields of the referenced content types to use as the source for Galleria.'),
);
}
}
return $form;
}