You are here

function _taxonomy_access_options_validate in Taxonomy Access Control 7

Form element validation handler for taxonomy option fields.

We use a property set in hook_field_widget_form_alter():

  • $element['#disallowed_defaults']

See also

options_field_widget_validate()

taxonomy_access_field_widget_form_alter()

Related topics

1 call to _taxonomy_access_options_validate()
taxonomy_access_options_validate in ./taxonomy_access.module
Form element validation handler for taxonomy options fields.

File

./taxonomy_access.create.inc, line 542
Implements the Add Tag (create) grant on editing forms.

Code

function _taxonomy_access_options_validate($element, &$form_state) {
  if ($element['#required'] && $element['#value'] == '_none') {
    form_error($element, t('!name field is required.', array(
      '!name' => $element['#title'],
    )));
  }

  // Clone the element and add in disallowed defaults.
  $el = $element;
  if (!empty($element['#disallowed_defaults'])) {
    if (empty($el['#value'])) {
      $el['#value'] = $element['#disallowed_defaults'];
    }
    elseif (is_array($el['#value'])) {
      $el['#value'] = array_unique(array_merge($el['#value'], $element['#disallowed_defaults']));
    }
    else {
      $el['#value'] = array_unique(array_merge(array(
        $el['#value'],
      ), $element['#disallowed_defaults']));
    }
  }

  // Transpose selections from field => delta to delta => field, turning
  // multiple selected options into multiple parent elements.
  $items = _options_form_to_storage($el);

  // Subsequent validation will be handled by hook_field_attach_validate().
  // Set the value in the form.
  form_set_value($element, $items, $form_state);
}