Commit 26bd380c authored by jurgenhaas's avatar jurgenhaas

Enhance the settings functionality and get the module ready for public release.

parent bdac50aa
......@@ -28,27 +28,49 @@ function colorbox_field_formatter_field_formatter_info() {
}
/**
* Implements hook_field_formatter_settings_form().
* Callback to provide an array for a select field containing all supported
* colorbox styles.
*
* @return array
*/
function colorbox_field_formatter_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) {
$settings = $instance['display'][$view_mode]['settings'];
$element = array();
function _colorbox_field_formatter_get_styles() {
$styles = array();
if (variable_get('colorbox_load', 0)) {
$styles['colorbox-load'] = t('Colorbox load');
$default_style = 'colorbox-load';
}
if (variable_get('colorbox_inline', 0)) {
$styles['colorbox-inline'] = t('Colorbox inline');
$default_style = 'colorbox-inline';
}
if (variable_get('colorbox_load', 0)) {
$styles['colorbox-load'] = t('Colorbox load');
}
if (module_exists('colorbox_node')) {
$styles['colorbox-node'] = t('Colorbox node');
$default_style = 'colorbox-node';
}
return $styles;
}
/**
* Callback to provide an arry for a select field containing all link types.
*
* @return array
*/
function _colorbox_field_formatter_get_link_types() {
return array(
'content' => t('Content'),
'manual' => t('Manually provide a link'),
);
}
/**
* Implements hook_field_formatter_settings_form().
*/
function colorbox_field_formatter_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) {
$settings = $instance['display'][$view_mode]['settings'];
$element = array();
$styles = _colorbox_field_formatter_get_styles();
$default_style = array_pop(array_keys($styles));
$element['colorbox_field_formatter_style'] = array(
'#title' => t('Style of colorbox'),
'#type' => 'select',
......@@ -56,19 +78,24 @@ function colorbox_field_formatter_field_formatter_settings_form($field, $instanc
'#options' => $styles,
);
$link_types = array(
'content' => t('Content'),
);
$element['colorbox_field_formatter_link_type'] = array(
'#title' => t('Link colorbox to'),
'#type' => 'select',
'#default_value' => $settings['colorbox_field_formatter_link_type'],
'#options' => $link_types,
'#options' => _colorbox_field_formatter_get_link_types(),
'#attributes' => array(
'class' => array('colorbox-field-formatter-link-type'),
),
);
$element['colorbox_field_formatter_link'] = array(
'#title' => t('URI'),
'#type' => 'textfield',
'#default_value' => $settings['colorbox_field_formatter_link'],
'#states' => array(
'visible' => array(
'select.colorbox-field-formatter-link-type' => array('value' => 'manual'),
),
),
);
$element['colorbox_field_formatter_width'] = array(
......@@ -107,8 +134,29 @@ function colorbox_field_formatter_field_formatter_settings_summary($field, $inst
$settings = $instance['display'][$view_mode]['settings'];
$summary = array();
// TODO: Go through the settings.
$summary[] = t('We will collect settings here');
$styles = _colorbox_field_formatter_get_styles();
$summary[] = '<strong>' . t('Style of colorbox') . '</strong> ' . $styles[$settings['colorbox_field_formatter_style']];
$types = _colorbox_field_formatter_get_link_types();
switch ($settings['colorbox_field_formatter_link_type']) {
case 'manual':
$summary[] = '<strong>' . t('Link to') . '</strong> ' . $settings['colorbox_field_formatter_link'];
break;
default:
$summary[] = '<strong>' . t('Link to') . '</strong> ' . $types[$settings['colorbox_field_formatter_link_type']];
break;
}
$summary[] = '<strong>' . t('Width') . '</strong> ' . $settings['colorbox_field_formatter_width'];
$summary[] = '<strong>' . t('Height') . '</strong> ' . $settings['colorbox_field_formatter_height'];
$summary[] = '<strong>' . t('iFrame Mode') . '</strong> ' . ($settings['colorbox_field_formatter_style'] ? t('Yes') : t('No'));
if (!empty($settings['colorbox_field_formatter_anchor'])) {
$summary[] = '<strong>' . t('Anchor') . '</strong> #' . $settings['colorbox_field_formatter_anchor'];
}
if (!empty($settings['colorbox_field_formatter_class'])) {
$summary[] = '<strong>' . t('Classes') . '</strong> ' . $settings['colorbox_field_formatter_class'];
}
return implode('<br />', $summary);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment