function name_field in Name Field 6
Implementation of hook_field().
File
- ./
name.module, line 785 - Defines an API for displaying and inputing names.
Code
function name_field($op, &$node, $field, &$items, $teaser, $page) {
switch ($op) {
case 'validate':
// Validation on required is done here.
// The max. length is done via Drupal.
// Min. components is done via name_element validation callback.
if ($field['required']) {
if (is_array($items)) {
foreach ($items as $delta => $item) {
if (!name_content_is_empty($item, $field)) {
return $items;
}
}
}
$error_element = empty($items[0]['_error_element']) ? '' : $items[0]['_error_element'] . '][';
$error_element .= $field['field_name'] . '[0]';
// TODO
form_set_error($error_element, t('%label is required.', array(
'%label' => $field['widget']['label'],
)));
}
return $items;
case 'sanitize':
foreach ($items as $delta => $item) {
foreach (_name_translations() as $key => $title) {
$items[$delta]['safe'][$key] = empty($item[$key]) ? '' : check_plain($item[$key]);
}
}
}
}