You are here

function conditional_fields_content_admin_field_controllable in Conditional Fields 6

Same name and namespace in other branches
  1. 6.2 conditional_fields.module \conditional_fields_content_admin_field_controllable()

Controllable field settings form

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

File

./conditional_fields.module, line 414
Content fields and groups visibility based on the values of user defined 'trigger' fields.

Code

function conditional_fields_content_admin_field_controllable(&$form, $type, $field_name, $available_fields, $allowed_values, $context) {
  $description = '<p>' . t('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. Only fields and groups within the same group as this one, and with <em>Allowed values</em> set, are available for control.', array(
    '@context' => $context,
  )) . '</p>';
  conditional_fields_content_admin_field_fieldset($form, $description, TRUE);
  $default_values = conditional_fields_available_fields_default_values($field_name, $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']];
    if (isset($default_values[$field['field_name']]) && $default_values[$field['field_name']] != FALSE) {
      $default_value = $default_values[$field['field_name']];
      $set = TRUE;
    }
    else {
      $default_value = 'conditional_field_no_value';
    }
    $form['conditional_fields'][$field['field_name']] = array(
      '#type' => 'select',
      '#multiple' => TRUE,
      '#title' => $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 %field-name.', array(
        '@edit-field' => url('admin/content/node-type/' . $type['url_str'] . '/fields/' . $field['field_name'], array(
          'query' => 'destination=admin/content/node-type/' . arg(3) . '/' . arg(4) . '/' . arg(5),
        )),
        '%field-name' => $field['field_name'],
      )),
      '#options' => $allowed_values[$field['field_name']],
      '#default_value' => $default_value,
    );
  }

  // Don't collapse the settings if we already have a configuration
  if ($set) {
    $form['conditional_fields']['#collapsed'] = FALSE;
  }
}