You are here

function conditional_fields_content_admin_field_validate in Conditional Fields 6

Same name and namespace in other branches
  1. 5 conditional_fields.module \conditional_fields_content_admin_field_validate()
  2. 6.2 conditional_fields.module \conditional_fields_content_admin_field_validate()

Check selection of values

2 string references to 'conditional_fields_content_admin_field_validate'
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 498
Content fields and groups visibility based on the values of user defined 'trigger' fields.

Code

function conditional_fields_content_admin_field_validate($form, &$form_state) {
  if ($form_state['values']['conditional_fields']) {
    $count_selected = 0;
    foreach ($form_state['values']['conditional_fields'] as $available_field => $trigger_values) {

      // Disallow more than one controlling field until properly supported
      if (count($trigger_values) > 1 || !$trigger_values['conditional_field_no_value']) {
        $count_selected++;
        if ($count_selected == 2) {
          form_set_error('conditional_fields', t('You cannot select more than one controlling field.'));
        }
      }

      // Disallow selecting Not set and values at the same time
      if ($trigger_values['conditional_field_no_value'] && count($trigger_values) > 1) {
        form_set_error('conditional_fields][' . $available_field, t('You cannot select "Not controlling" and other values at the same time.'));
      }
    }
  }
  else {

    // Warn user on allowed values change
    if (!$GLOBALS['content_copy'] && !empty($form['#controlled_fields']) && $form_state['values']['allowed_values'] != $form_state['#field_info'][$form['values']['field_name']]['allowed_values']) {
      drupal_set_message(t('If you changed or removed any allowed value from the field, you might have to review its controlled fields and fieldgroups settings.'), 'warning');
    }
  }
}