function conditional_fields_content_admin_field in Conditional Fields 5
Same name and namespace in other branches
- 6.2 conditional_fields.module \conditional_fields_content_admin_field()
- 6 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 252
Code
function conditional_fields_content_admin_field(&$form) {
$type = 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'];
}
}
// Get available fields, which are:
// - Not this one :)
// - Fields not controlled by this one
// - Fields not in a group (if this field isn't in a group), or fields in the same group.
// Since the latter can change depending on user choice, we allow them for now, and check them on validation
foreach ($type['fields'] as $field) {
if ($field['field_name'] != $form['field_name']['#value'] && !$controlled_fields[$field['field_name']]) {
if ($allowed_values[$field['field_name']] = conditional_fields_allowed_values($field)) {
$available_fields[$field['field_name']] = $field;
}
}
}
// Add extra validation funcion
$form['#validate'] = array_merge(array(
'conditional_fields_content_admin_field_validate' => array(
$controlled_fields,
),
), $form['#validate']);
if (isset($available_fields)) {
// Add controlled fields notice
if (!empty($controlled_fields)) {
foreach ($controlled_fields as $field => $trigger_values) {
if (substr($field, 0, 6) == 'group_' && $form['widget']['group']) {
// It's a group
$rows[] = array(
$field,
t('group'),
'<a href="' . url('admin/content/types/' . $type['type'] . '/groups/' . $field . '/edit', NULL, 'conditional-fields-settings') . '">' . t('edit') . '</a>',
);
}
else {
// It's a field
$rows[] = array(
$field,
t('field'),
'<a href="' . url('admin/content/types/' . $type['type'] . '/fields/' . $field . '/edit', NULL, 'conditional-fields-settings') . '">' . t('edit') . '</a>',
);
}
}
}
if ($rows) {
$description = t('<p>Below is a list of all fields and groups controlled by this field. If you want to make this field controllable, you have to clear the settings for each controlled field.</p>') . theme('table', array(
t('Name'),
t('Type'),
t('Options'),
), $rows);
}
else {
// Add extra submission funcion
$form['#submit'] = array_merge(array(
'conditional_fields_forms_submit' => array(
$type['type'],
$form['field_name']['#value'],
),
), $form['#submit']);
}
$form['widget'] = _conditional_fields_build_form($type, $form['widget'], $form['field_name']['#value'], $controlled_fields, $available_fields, $allowed_values, 'field', $description);
}
return;
}