function name_element_validate in Name Field 6
Same name and namespace in other branches
- 8 name.module \name_element_validate()
- 7 name.module \name_element_validate()
1 string reference to 'name_element_validate'
- name_elements in ./
name.module - Implementation of hook_elements().
File
- ./
name.module, line 424 - Defines an API for displaying and inputing names.
Code
function name_element_validate($element, &$form_state) {
$minimum_components = array_filter($element['#minimum_components']);
$labels = array();
foreach ($element['#components'] as $key => $component) {
if (!isset($component['exclude'])) {
$labels[$key] = $component['title'];
}
}
$item = $element['#value'];
$empty = name_content_is_empty($item, NULL);
$item_components = array();
foreach (_name_translations() as $key => $title) {
if (isset($labels[$key]) && !empty($item[$key])) {
$item_components[$key] = $item[$key];
}
}
if (!$empty && count($minimum_components) != count(array_intersect_key($minimum_components, $item_components))) {
$missing_labels = array_diff_key(array_intersect_key($labels, $minimum_components), $item_components);
$label = empty($element['#title']) ? empty($element['#label']) ? 'Field' : $element['#label'] : $element['#title'];
form_error($element[key($missing_labels)], t('%name also requires the following parts: %components.', array(
'%name' => $label,
'%components' => implode(', ', $missing_labels),
)));
}
return $element;
}