You are here

function taxonomy_workbench_access_default_form_alter in Workbench Access 7

Executes a form alter on a specific FieldAPI form element.

File

modules/taxonomy.workbench_access.inc, line 232
Taxonomy integration for Workbench Access.

Code

function taxonomy_workbench_access_default_form_alter(&$form, &$form_state, $options) {
  foreach ($form['workbench_access_fields']['#value'] as $item) {

    // If the element isn't set, we can't do anything.
    if (!isset($form[$item][$form[$item]['#language']])) {
      continue;
    }

    // Set the element to be altered.
    $element =& $form[$item][$form[$item]['#language']];

    // Set the options for the form.
    if (isset($form[$item][$form[$item]['#language']]['#options'])) {
      foreach ($element['#options'] as $key => $value) {
        if ($key != '_none' && !isset($options[$key])) {
          unset($element['#options'][$key]);
        }
      }
    }
    elseif (isset($element['#autocomplete_path'])) {
      $element['#autocomplete_path'] = 'workbench_access/taxonomy_autocomplete/' . $item . '/' . $form['#node']->type;

      // We need our own validation, too.
      $element['#element_validate'][] = 'workbench_access_autocomplete_validate';
    }
  }
}