function office_hours_field in Office Hours 5
Same name and namespace in other branches
- 6.2 office_hours.module \office_hours_field()
- 6 office_hours.module \office_hours_field()
implementation of hook_field Define the behavior of a field type.
Parameters
$op: What kind of action is being performed. Possible values.
&$node: The node the action is being performed on. This argument is passed by reference for performance only; do not modify it.
$field: The field the action is being performed on.
&$node_field: The contents of the field in this node. Changes to this variable will be saved back to the node object.
Return value
This varies depending on the operation.
- The "load" operation should return an object containing extra values to be merged into the node object.
- The "view" operation should return a string containing an HTML representation of the field data.
- The "insert", "update", "delete", "validate", and "submit" operations have no return value.
In most cases, only "validate" operations is relevant ; the rest have default implementations in content_field() that usually suffice.
File
- ./
office_hours.module, line 210 - Creates a field and widget for inserting working or office hours per day
Code
function office_hours_field($op, &$node, $field, &$node_field, $teaser, $page) {
switch ($op) {
case 'view':
$context = $teaser ? 'teaser' : 'full';
$formatter = isset($field['display_settings'][$context]['format']) ? $field['display_settings'][$context]['format'] : 'default';
$items = array();
foreach ($node_field as $delta => $item) {
$items[$delta]['view'] = content_format($field, $item, $formatter, $node);
}
return theme('field', $node, $field, $items, $teaser, $page);
case 'validate':
if ($field['valhrs'] == 1) {
if (is_array($node_field)) {
foreach ($node_field as $delta => $item) {
$error_field = $field['field_name'] . '][' . $delta . '][endhours';
$starthours = tf_to_mil($item['starthours']);
$endhours = tf_to_mil($item['endhours']);
if ($starthours >= $endhours) {
form_set_error($error_field, t('Closing hours are earlier than opening hours'));
}
}
}
}
break;
}
}