function office_hours_field_settings in Office Hours 5
Same name and namespace in other branches
- 6.2 office_hours.module \office_hours_field_settings()
- 6 office_hours.module \office_hours_field_settings()
implementation of hook_field Handle the parameters for a field.
Parameters
$op:
$field: The field on which the operation is to be performed.
Return value
This varies depending on the operation.
- "form": an array of form elements to add to the settings page.
- "validate": no return value. Use form_set_error().
- "save": an array of names of form elements to be saved in the database.
- "database columns": an array keyed by column name, with arrays of column information as values.
- "callbacks": an array describing the field's behaviour regarding hook_field operations. The array is keyed by hook_field operations ('view', 'validate'...) and has the following possible values : CONTENT_CALLBACK_NONE : do nothing for this operation CONTENT_CALLBACK_CUSTOM : use the behaviour in hook_field(operation) CONTENT_CALLBACK_DEFAULT : use content.module's default bahaviour Note : currently only the 'view' operation implements this feature.
- "tables": an array of 'tables' definitions as expected by views.module (see Views Documentation).
- "arguments": an array of 'arguments' definitions as expected by views.module (see Views Documentation).
- "filters": an array of 'filters' definitions as expected by views.module (see Views Documentation). When providing several filters, it is recommended to use the 'name' attribute in order to let the user distinguish between them. If no 'name' is specified for a filter, the key of the filter will be used instead.
File
- ./
office_hours.module, line 67 - Creates a field and widget for inserting working or office hours per day
Code
function office_hours_field_settings($op, $field) {
switch ($op) {
case 'form':
$options = _create_hours_arr($field, FALSE);
$optlim = _create_hours_arr($field);
$form = array();
$form['hoursformat'] = array(
'#type' => 'select',
'#title' => t('Hours format'),
'#options' => array(
t('24 hrs.'),
t('12 hrs'),
),
'#default_value' => $field['hoursformat'] ? $field['hoursformat'] : 0,
'#required' => FALSE,
'#description' => t('Format of the clock. IMPORTANT NOTE: if you do not select "Multiple values", you can enter only one day.'),
);
$form['granularity'] = array(
'#type' => 'select',
'#title' => t('granularity of time'),
'#options' => array(
0 => t('Hours'),
30 => t('Half hours'),
15 => t('Quarter hours'),
),
'#default_value' => $field['granularity'] ? $field['granularity'] : 0,
'#required' => FALSE,
'#description' => t('Allow inserting quarter hours, half hours, or only hours of the day'),
);
$form['limitstart'] = array(
'#type' => 'select',
'#title' => t('Limit widget start hours'),
'#options' => $options,
'#default_value' => $field['limitstart'] ? $field['limitstart'] : FALSE,
'#required' => FALSE,
'#description' => t('Set the allowed start hours. Note: if you just changed the clock format, please submit before changing this.'),
);
$form['limitend'] = array(
'#type' => 'select',
'#title' => t('Limit widget end hours'),
'#options' => $options,
'#default_value' => $field['limitend'] ? $field['limitend'] : FALSE,
'#required' => FALSE,
'#description' => t('Set the allowed end hours. Note: if you just changed the clock format, please submit before changing this'),
);
$form['defaultstart'] = array(
'#type' => 'select',
'#title' => t('Start hours default'),
'#options' => $optlim,
'#default_value' => $field['defaultstart'] ? $field['defaultstart'] : FALSE,
'#required' => FALSE,
'#description' => t('Use this field if you want for specific hours to show by default.'),
);
$form['defaultend'] = array(
'#type' => 'select',
'#title' => t('End hours default'),
'#options' => $optlim,
'#default_value' => $field['defaultend'] ? $field['defaultend'] : FALSE,
'#required' => FALSE,
'#description' => t('Use this field if you want for specific hours to show by default.'),
);
$form['valhrs'] = array(
'#type' => 'checkbox',
'#title' => t('Validate hours'),
//'#options' => array('validatehrs'=> t('Check that closing hours are not earlier than opening hours')),
'#required' => FALSE,
'#default_value' => isset($field['valhrs']) ? $field['valhrs'] : 0,
'#description' => t('Check that closing hours are not earlier than opening hours. Please note that this will work as long as the opening hours are not through midnight.'),
);
return $form;
case 'validate':
if ($field['defaultend'] != 'none' && $field['defaultstart'] != 'none') {
if (tf_to_mil($field['defaultend']) <= tf_to_mil($field['defaultstart'])) {
form_set_error('defaultend', 'Default ending hours are earlier than start hours');
}
}
if ($field['limitend'] != 'none' && $field['limitstart'] != 'none') {
if (tf_to_mil($field['limitend']) <= tf_to_mil($field['limitstart'])) {
form_set_error('limitend', 'Limit ending hours are earlier than start hours');
}
}
break;
case 'save':
return array(
'hoursformat',
'granularity',
'limitstart',
'limitend',
'defaultstart',
'defaultend',
'valhrs',
);
case 'database columns':
$columns = array(
'day' => array(
'type' => 'int',
'length' => 1,
'unsigned' => TRUE,
),
'starthours' => array(
'type' => 'varchar',
'length' => 10,
'not null' => FALSE,
'sortable' => TRUE,
),
'endhours' => array(
'type' => 'varchar',
'length' => 10,
'not null' => FALSE,
'sortable' => TRUE,
),
);
return $columns;
case 'callbacks':
return array(
'view' => CONTENT_CALLBACK_CUSTOM,
);
case 'tables':
$tables = content_views_field_tables($field);
return $tables;
case 'arguments':
$arguments = content_views_field_arguments($field);
return $arguments;
case 'filters':
return array(
'substring' => array(
'operator' => 'views_handler_operator_like',
'handler' => 'views_handler_filter_like',
),
'alpha_order' => array(
'name' => 'alphabetical order',
'operator' => 'views_handler_operator_gtlt',
),
);
}
}