You are here

function _conditional_fields_build_form in Conditional Fields 5

This adds conditional fields settings in the field and fieldgroup editing forms. Valid choices for $op are 'field' and 'group'

2 calls to _conditional_fields_build_form()
conditional_fields_content_admin_field in ./conditional_fields.module
Alteration of the field editing form
conditional_fields_fieldgroup_edit_group_form in ./conditional_fields.module
Alteration of the fieldgroup editing form

File

./conditional_fields.module, line 348

Code

function _conditional_fields_build_form($type, $form, $control_field, $controlled_fields, $available_fields, $allowed_values, $op, $description = NULL) {
  if (!$description) {
    $description = t('<p>Choose which allowed values of available controlling fields will trigger this @context, making it visible both in node editing and view. If no value is set, the @context will be always visible.</p>', array(
      '@context' => t($op),
    )) . $description;
  }
  $form['conditional_fields'] = array(
    '#type' => 'fieldset',
    '#title' => t('Conditional fields settings'),
    '#tree' => TRUE,
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#description' => $description,
    '#weight' => 8,
  );
  if (empty($controlled_fields)) {

    // Disallow nested conditional fields
    $default_values = conditional_fields_default_values($control_field, $available_fields);

    // Create selection lists
    foreach ($available_fields as $field) {
      $allowed_values[$field['field_name']] = array(
        'conditional_field_no_value' => t('- Not controlling -'),
      ) + $allowed_values[$field['field_name']];
      $form['conditional_fields'][$field['field_name']] = array(
        '#type' => 'select',
        '#multiple' => TRUE,
        '#title' => t($field['widget']['label']) . ' (' . $field['field_name'] . ')',
        // To do: set right url for groups
        '#description' => t('<a href="@edit-field">Edit the allowed values</a> of the %field-name field.', array(
          '@edit-field' => url('admin/content/types/' . $type['url_str'] . '/fields/' . $field['field_name'], 'destination=admin/content/types/' . arg(3) . '/fields/' . arg(5), 'edit-allowed-values'),
          '%field-name' => t($field['widget']['label']),
        )),
        '#options' => $allowed_values[$field['field_name']],
        '#default_value' => isset($default_values[$field['field_name']]) && $default_values[$field['field_name']] != FALSE ? $default_values[$field['field_name']] : 'conditional_field_no_value',
      );
    }
  }
  return $form;
}