function office_hours_field_formatter_settings_form in Office Hours 7
Implements hook_field_formatter_settings_form().
File
- includes/
office_hours.formatter.inc, line 24 - Implements the office_hours formatter.
Code
function office_hours_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) {
$display = $instance['display'][$view_mode];
$settings = _office_hours_field_formatter_defaults($instance['display'][$view_mode]['settings']);
$form = array();
/*
// Find timezone fields, to be used in 'Current status'-option.
$fields = field_info_instances( (isset($form['#entity_type']) ? $form['#entity_type'] : NULL), (isset($form['#bundle']) ? $form['#bundle'] : NULL));
$timezone_fields = array();
foreach ($fields as $field_name => $timezone_instance) {
if ($field_name == $field['field_name']) {
continue;
}
$timezone_field = field_read_field($field_name);
if (in_array($timezone_field['type'], array('tzfield'))) {
$timezone_fields[$timezone_instance['field_name']] = $timezone_instance['label'] . ' (' . $timezone_instance['field_name'] . ')';
}
}
if ($timezone_fields) {
$timezone_fields = array('' => '<None>') + $timezone_fields;
}
*/
// @TODO: The settings could go under the several 'core' settings,
// as above in the implemented hook_FORMID_form_alter functions.
$form = array(
'#type' => 'fieldset',
'#title' => t('Office hours formatter settings'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#weight' => 5,
);
/* // dec-2012: converted from checkbox to selectlist.
$form['showclosed'] = array(
'#type' => 'checkbox',
'#title' => t('Show empty days'),
'#required' => FALSE,
'#default_value' => $settings['showclosed'],
'#description' => t('Show empty days on the field.'),
);
*/
$form['showclosed'] = array(
'#type' => 'select',
'#title' => t('Number of days to show'),
'#options' => array(
'all' => t('Show all days'),
'open' => t('Show only open days'),
'next' => t('Show next open day'),
'none' => t('Hide all days'),
),
'#default_value' => $settings['showclosed'],
'#description' => t('The days to show in the formatter. Useful in combination with the Current Status block.'),
);
// First day of week, copied from system.variable.inc.
$form['date_first_day'] = array(
'#type' => 'select',
'#options' => date_week_days(TRUE),
'#title' => t('First day of week'),
'#default_value' => $settings['date_first_day'],
);
$form['daysformat'] = array(
'#type' => 'select',
'#title' => t('Day notation'),
'#options' => array(
'long' => t('long'),
'short' => t('short'),
'number' => t('number'),
'none' => t('none'),
),
'#default_value' => $settings['daysformat'],
);
$form['hoursformat'] = array(
'#type' => 'select',
'#title' => t('Hours format'),
'#options' => array(
2 => t('24 hrs') . ' (09:00)',
0 => t('24 hrs') . ' (9:00)',
1 => t('12 hrs') . ' (9:00 am)',
3 => t('12 hrs') . ' (9:00 a.m.)',
),
'#default_value' => $settings['hoursformat'],
'#required' => FALSE,
'#description' => t('Format of the clock in the formatter.'),
);
$form['compress'] = array(
'#title' => t('Compress all hours of a day into one set'),
'#type' => 'checkbox',
'#default_value' => $settings['compress'],
'#description' => t('Even if more hours is allowed, you might want to show a compressed form. E.g., 7:00-12:00, 13:30-19:00 becomes 7:00-19:00.'),
'#required' => FALSE,
);
$form['grouped'] = array(
'#title' => t('Group consecutive days with same hours into one set'),
'#type' => 'checkbox',
'#default_value' => $settings['grouped'],
'#description' => t('E.g., Mon: 7:00-19:00; Tue: 7:00-19:00 becomes Mon-Tue: 7:00-19:00.'),
'#required' => FALSE,
);
$form['closedformat'] = array(
'#type' => 'textfield',
'#size' => 30,
'#title' => t('Empty days notation'),
'#default_value' => $settings['closedformat'],
'#required' => FALSE,
'#description' => t('Format of empty (closed) days. You can use translatable text and HTML in this field.'),
);
// Taken from views_plugin_row_fields.inc.
$form['separator_days'] = array(
'#title' => t('Separators'),
'#type' => 'textfield',
'#size' => 10,
'#default_value' => $settings['separator_days'],
'#description' => t('This separator will be placed between the days. Use '<br>' to show each day on a new line.'),
);
$form['separator_grouped_days'] = array(
'#type' => 'textfield',
'#size' => 10,
'#default_value' => $settings['separator_grouped_days'],
'#description' => t('This separator will be placed between the labels of grouped days.'),
);
$form['separator_day_hours'] = array(
'#type' => 'textfield',
'#size' => 10,
'#default_value' => $settings['separator_day_hours'],
'#description' => t('This separator will be placed between the day and the hours.'),
);
$form['separator_hours_hours'] = array(
'#type' => 'textfield',
'#size' => 10,
'#default_value' => $settings['separator_hours_hours'],
'#description' => t('This separator will be placed between the hours of a day.'),
);
$form['separator_more_hours'] = array(
'#type' => 'textfield',
'#size' => 10,
'#default_value' => $settings['separator_more_hours'],
'#description' => t('This separator will be placed between the hours and more_hours of a day.'),
);
// Show a 'Current status' option.
$form['current_status'] = array(
'#title' => t('Current status'),
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$form['current_status']['position'] = array(
'#type' => 'select',
'#title' => t('Current status position'),
'#options' => array(
'hide' => t('Hidden'),
'before' => t('Before hours'),
'after' => t('After hours'),
),
'#default_value' => $settings['current_status']['position'],
'#description' => t('Where should the current status be located?'),
);
$form['current_status']['open_text'] = array(
'#title' => t('Formatting'),
'#type' => 'textfield',
'#size' => 40,
'#default_value' => $settings['current_status']['open_text'],
'#description' => t('Format of the message displayed when currently open. You can use translatable text and HTML in this field.'),
);
$form['current_status']['closed_text'] = array(
'#type' => 'textfield',
'#size' => 40,
'#default_value' => $settings['current_status']['closed_text'],
'#description' => t('Format of message displayed when currently closed. You can use translatable text and HTML in this field.'),
);
/*
if ($timezone_fields) {
$form['timezone_field'] = array(
'#type' => 'select',
'#title' => t('Timezone') . ' ' . t('Field'),
'#options' => $timezone_fields,
'#default_value' => $settings['timezone_field'],
'#description' => t('Should we use another field to set the timezone for these hours?'),
);
}
else {
$form['timezone_field'] = array(
'#type' => 'hidden',
'#value' => $settings['timezone_field'],
);
}
*/
return $form;
}