function content_multiple_value_after_build in Content Construction Kit (CCK) 6.3
After build callback for multiple value fields.
1 call to content_multiple_value_after_build()
- content_multiple_value_after_build_proxy in ./
content.module - Proxy function to call content_multiple_value_after_build(), because it might not be included yet when the form is processed and invokes the callback.
File
- includes/
content.node_form.inc, line 274 - Create fields' form for a content type.
Code
function content_multiple_value_after_build($elements, &$form_state) {
$items_map = array();
foreach (element_children($elements) as $delta) {
// Find delta items for this field when the form if being processed for validation.
if (isset($elements[$delta]) && $elements[$delta] && is_numeric($delta) && !empty($elements[$delta]['#needs_validation'])) {
// Find items that have been flagged for removal.
if (isset($elements[$delta]['_remove']) && !empty($elements[$delta]['_remove']['#value'])) {
// Update the value in the #post attribute of the elements.
$post =& $elements[$delta]['#post'];
foreach ($elements[$delta]['#parents'] as $name) {
$post =& $post[$name];
}
$post = array(
'_weight' => $elements[$delta]['_weight']['#value'],
'_remove' => 1,
);
// Alter the value of this element and children recursively.
content_multiple_value_after_build_recursive($elements[$delta], $elements[$delta]['#post']);
$items_map[$delta] = TRUE;
}
else {
$items_map[$delta] = FALSE;
}
}
}
// If the multiple values field is required, then make sure there's at
// least one item not flagged for removal. This is necessary to point
// the user to the correct form element when the validation error is
// issued from content_multiple_value_nodeapi_validate().
$items_count = count($items_map);
if (!empty($elements['#required']) && $items_count > 0) {
// If the number of removed items is equal to the total number of
// items, then we'll reset the '_remove' flag of the first item, and
// that will be used to point the user when the required field error
// is issued by content_multiple_value_nodeapi_validate().
if ($items_count == count(array_filter($items_map))) {
$delta = key($items_map);
if (isset($elements[$delta]['_remove'])) {
$elements[$delta]['_remove']['#value'] = 0;
}
}
}
return $elements;
}