function office_hours_field_settings_form in Office Hours 7
Implements hook_field_settings_form().
Handle the global parameters for a field.
File
- includes/
office_hours.field.inc, line 102 - Implements the office_hours Field.
Code
function office_hours_field_settings_form($field, $instance, $has_data) {
$settings = $field['settings'];
// Adapt field settings to this special case.
$my_settings = $field['settings'];
$my_settings['valhrs'] = FALSE;
$my_settings['limitstart'] = '';
$my_settings['limitend'] = '';
$my_settings['hoursformat'] = 'H';
$hours = _office_hours_show_ampm(_office_hours_field_widget_hours($my_settings));
$form = array();
$form['#element_validate'] = array(
'_office_hours_field_settings_form_validate',
);
$description = t('The maximum number of blocks, that are allowed per day.');
$description .= '<br/><strong>' . t('Warning! Lowering this setting after data has been created could result in the loss of data!') . '</strong><br/>';
$description .= t('Be careful when using more then 2 blocks per day, since not all external services (like Google Places) support this.');
$form['cardinality'] = array(
'#type' => 'select',
'#title' => t('Number of blocks'),
// @todo for 'multiple blocks per day': add support for FIELD_CARDINALITY_UNLIMITED.
// '#options' => array(FIELD_CARDINALITY_UNLIMITED => t('Unlimited')) + drupal_map_assoc(range(1, 10)),
// '#options' => drupal_map_assoc(range(1, 2)),
'#options' => drupal_map_assoc(range(1, 12)),
'#default_value' => $settings['cardinality'],
'#description' => $description,
);
// Mar-2013: Convert (old) checkbox "Add more hours" to (new) selectlist.
// @todo for 'multiple blocks per day': remove, after create hook_update_N().
if (isset($settings['addhrs'])) {
$form['addhrs'] = array(
// '#type' => 'checkbox',
'#type' => 'hidden',
'#title' => t('Display the "Add more hours" link'),
'#required' => FALSE,
'#default_value' => $settings['addhrs'],
'#description' => t('Make it possible to use 2 hour block for each day instead of one.'),
);
if (!is_null($settings['addhrs']) && $settings['addhrs'] == 0 && $settings['cardinality'] == 2) {
$form['addhrs']['#default_value'] = NULL;
$form['cardinality']['#default_value'] = 1;
}
}
// 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'],
'#description' => t('First day in the widget. (A separate setting exists for the formatter.)'),
);
$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 widget.'),
);
$form['granularity'] = array(
'#type' => 'select',
'#title' => t('Granularity of time'),
'#options' => array(
'60' => t('hours'),
'30' => t('half hours'),
'15' => t('quarter hours'),
'5' => t('5 minute intervals'),
'1' => t('minutes'),
),
'#default_value' => $settings['granularity'],
'#required' => FALSE,
'#description' => t('Restrict the input to fixed fractions of an hour.'),
);
$form['comment'] = array(
'#type' => 'checkbox',
'#title' => t('Allow a comment per time slot'),
'#required' => FALSE,
'#default_value' => $settings['comment'],
);
$form['valhrs'] = array(
'#type' => 'checkbox',
'#title' => t('Validate hours'),
'#required' => FALSE,
'#default_value' => $settings['valhrs'],
'#description' => t('Assure that endhours are later then starthours. Please note that this will work as long as the opening hours are not through midnight.'),
);
$form['limitstart'] = array(
'#type' => 'select',
'#title' => t('Limit widget hours - from'),
'#description' => t('Restrict the hours available - select options will start from this hour.'),
'#default_value' => $settings['limitstart'],
'#options' => $hours,
);
$form['limitend'] = array(
'#type' => 'select',
'#title' => t('Limit widget hours - until'),
'#description' => t('Restrict the hours available - select options will end at this hour.'),
'#default_value' => $settings['limitend'],
'#options' => $hours,
);
/*
// @Todo: activate this, to Show $form['limitstart'] and $form['limitend'] using the normal widget.
$form_state = NULL;
$default_value_field = $field;
$default_value_field['settings']['granularity'] = '60';
$langcode = 'und';
$items = array();
$delta = 0;
$element = NULL;
$elements = office_hours_field_widget_form($form, $form_state, $default_value_field, $instance, $langcode, $items, $delta, $element);
$form['limits'] = $elements[0];
$form['limits']['#dayname'] = 'Limit widget hours';
$form['limits']['#description'] = t('Restrict the hours available - select options will be between these hours.');
$form['limits']['#default_value'] = array(
'day' => 0,
'daydelta' => 0,
'starthours' => $settings['limitstart'],
'endhours' => $settings['limitend'],
);
*/
return $form;
}