function bulk_photo_nodes_required_optional in Bulk File Nodes 7
Set required/optional bulk photo node fields.
1 call to bulk_photo_nodes_required_optional()
- bulk_photo_nodes_add_form in ./
bulk_photo_nodes.module - Form constructor for final step of bpn_multistep_form().
File
- ./
bulk_photo_nodes.module, line 491 - hooks and helper functions for bulk photo node.
Code
function bulk_photo_nodes_required_optional(&$form, &$form_state) {
if (empty($form_state['values']['override_fields']['fields'])) {
return;
}
$override_node = (object) $form_state['values']['override_fields']['fields'];
$override_node->type = $form_state['node_type'];
$parent_fields_all = element_children($form['nodes'][0]['right']);
$parent_fields = array_diff($parent_fields_all, array(
'node',
));
foreach (array_keys($form_state['input']['override_fields']['fields']) as $field_name) {
// Check if batch field has a value.
$field_has_value = bulk_photo_nodes_check_field_empty($field_name, $override_node);
// If the batch field has a value, set the respective node subform field
// as optional.
foreach (element_children($form['nodes']) as $key) {
// Check for parent fields first, then fields in the collapsed fieldset.
// @todo Find cleaner, DRY way to do this.
if (in_array($field_name, $parent_fields)) {
if (bulk_photo_nodes_is_required($form['nodes'][$key]['right'][$field_name])) {
if ($field_has_value) {
bulk_photo_nodes_recursive_set_optional($form['nodes'][$key]['right'][$field_name]);
}
else {
bulk_photo_nodes_recursive_set_required($form['nodes'][$key]['right'][$field_name]);
}
}
}
else {
if (bulk_photo_nodes_is_required($form['nodes'][$key]['right']['node'][$field_name])) {
if ($field_has_value) {
bulk_photo_nodes_recursive_set_optional($form['nodes'][$key]['right']['node'][$field_name]);
}
else {
bulk_photo_nodes_recursive_set_required($form['nodes'][$key]['right']['node'][$field_name]);
}
}
}
}
}
}