function conditional_fields_content_admin_field in Conditional Fields 6
Same name and namespace in other branches
- 5 conditional_fields.module \conditional_fields_content_admin_field()
- 6.2 conditional_fields.module \conditional_fields_content_admin_field()
Alteration of the field editing form
1 call to conditional_fields_content_admin_field()
- conditional_fields_form_alter in ./
conditional_fields.module - Implementation of hook_form_alter().
File
- ./
conditional_fields.module, line 319 - Content fields and groups visibility based on the values of user defined 'trigger' fields.
Code
function conditional_fields_content_admin_field(&$form) {
if (!user_access('administer conditional fields')) {
return;
}
$type = (array) content_types($form['type_name']['#value']);
// Load conditional fields data.
$data = conditional_fields_load_data($type['type']);
// Get all fields controlled by this one.
$controlled_fields = array();
foreach ($data as $row) {
if ($row['control_field_name'] == $form['field_name']['#value']) {
$controlled_fields[$row['field_name']] = $row['trigger_values'];
}
}
// Build controlling field form. Return here because nested conditional fields are not supported.
if (!empty($controlled_fields)) {
$form['#controlled_fields'] = $controlled_fields;
// Add validation function
$form['#validate'] = array_merge(array(
'conditional_fields_content_admin_field_validate',
), $form['#validate']);
conditional_fields_content_admin_field_controlling($form['widget'], $type, $controlled_fields);
return;
}
// Check if field is in a group
if (isset($form['widget']['group'])) {
$controlled_field_in_group = $form['widget']['group']['#value'];
}
// Get available fields, which are:
foreach ($type['fields'] as $field) {
// - Not this one :)
if ($field['field_name'] == $form['field_name']['#value']) {
continue;
}
// - AND fields not in a group (if this field isn't in a group), or fields in the same group.
if (isset($controlled_field_in_group)) {
if ($controlled_field_in_group != conditional_fields_get_group($field['type_name'], $field['field_name'])) {
continue;
}
}
// - AND with Allowed values
if (!($allowed_values[$field['field_name']] = content_allowed_values($field))) {
continue;
}
$available_fields[$field['field_name']] = $field;
}
if (isset($available_fields)) {
conditional_fields_content_admin_field_controllable($form['widget'], $type, $form['field_name']['#value'], $available_fields, $allowed_values, 'field');
// Add validation function
$form['#validate'] = array_merge(array(
'conditional_fields_content_admin_field_validate',
), $form['#validate']);
// Add submission function
$form['#submit'] = array_merge(array(
'conditional_fields_forms_submit',
), $form['#submit']);
}
return;
}