You are here

function term_permissions_field_widget_validate in Taxonomy Term Permissions 7

Form element validation handler for taxonomy term reference element.

1 string reference to 'term_permissions_field_widget_validate'
term_permissions_form_alter in ./term_permissions.module
Implements hook_form_alter().

File

./term_permissions.module, line 343
Allows access to terms in a vocabulary to be limited by user or role.

Code

function term_permissions_field_widget_validate($element, &$form_state) {
  if (is_array($element['#default_value']) && !empty($element['#default_value'])) {
    global $user;
    $items = array();
    foreach ($element['#default_value'] as $tid) {
      if (!term_permissions_allowed($tid, $user)) {
        $items[] = array(
          'tid' => $tid,
        );
      }
    }
    if (!empty($items)) {
      $items = array_merge($items, _options_form_to_storage($element));
      form_set_value($element, $items, $form_state);
    }
  }
}