You are here

function conditional_fields_fieldgroup_group_edit_form in Conditional Fields 6.2

Same name and namespace in other branches
  1. 6 conditional_fields.module \conditional_fields_fieldgroup_group_edit_form()

Alteration of the fieldgroup editing form

1 call to conditional_fields_fieldgroup_group_edit_form()
conditional_fields_form_alter in ./conditional_fields.module
Implementation of hook_form_alter().

File

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

Code

function conditional_fields_fieldgroup_group_edit_form(&$form) {
  if (!user_access('administer conditional fields')) {
    return;
  }

  // A group that contains fields controlling or controlled by fields in other groups or no groups at all,
  // cannot be a controlled group.
  if ($data = conditional_fields_load_data($form['#content_type']['type'])) {
    $groups = fieldgroup_groups($form['#content_type']['type']);
    $group = $groups[$form['group_name']['#default_value']];
    foreach ($data as $row) {
      if (isset($group['fields'][$row['field_name']]) xor isset($group['fields'][$row['control_field_name']])) {
        return;
      }
    }
  }

  // Find fields with allowed values which are not inside a group or are in the same group of this group.
  foreach ($form['#content_type']['fields'] as $field) {
    $in_group = fieldgroup_get_group($form['#content_type']['type'], $field['field_name']);
    if (!$in_group || $in_group == $form['parent']['#default_value']) {
      if ($allowed_values[$field['field_name']] = conditional_fields_allowed_values($field)) {
        $available_fields[$field['field_name']] = $field;
      }
    }
  }
  if (isset($available_fields)) {
    $default_values = conditional_fields_available_fields_default_values($form['group_name']['#default_value'], $available_fields);

    // Add the fieldset to the form
    $form['widget']['conditional_fields'] = array(
      '#type' => 'fieldset',
      '#title' => t('Conditional fields settings'),
      '#tree' => TRUE,
      '#collapsible' => TRUE,
      '#collapsed' => empty($default_values),
      '#weight' => 8,
      '#attributes' => array(
        'id' => 'conditional-fields-settings',
      ),
    );
    $form['widget']['conditional_fields']['available_fields'] = conditional_fields_content_admin_field_controllable($form['#content_type'], $default_values, $available_fields, $allowed_values, 'group');

    // Add validation function
    $form['#validate'][] = 'conditional_fields_content_admin_field_validate';

    // Add submission function
    $form['#submit'] = array_merge(array(
      'conditional_fields_forms_submit',
    ), $form['#submit']);
  }
  return;
}