hook_field($op, &$node, $field, &$node_field, $teaser, $page)
cck.pre-rename/field.php, line 200
Define the behavior of a field type.
In most cases, only "validate" operations is relevant ; the rest have default implementations in content_field() that usually suffice.
$op What kind of action is being performed. Possible values:
$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.
This varies depending on the operation.
| Name | Description |
|---|---|
| Hooks | Allow modules to interact with the Drupal core. |
<?php
function hook_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':
$allowed_values = text_allowed_values($field);
if (is_array($items)) {
foreach ($items as $delta => $item) {
$error_field = $field['field_name']. ']['. $delta.'][value';
if ($item['value'] != '') {
if (count($allowed_values) && !array_key_exists($item['value'], $allowed_values)) {
form_set_error($error_field, t('Illegal value for %name.', array('%name' => t($field['widget']['label']))));
}
}
}
}
break;
}
}
?>