You are here

function term_permissions_submit in Taxonomy Term Permissions 6

Same name and namespace in other branches
  1. 7 term_permissions.module \term_permissions_submit()

Additional submit function for the term form. This occurs when a term is added or updated.

Parameters

$form: The current form array.

$form_state: The state of the current form.

1 string reference to 'term_permissions_submit'
term_permissions_form_alter in ./term_permissions.module
Implementation of hook_form_alter()

File

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

Code

function term_permissions_submit($form, &$form_state) {

  // For each user, save the term ID and the user ID.
  db_query("DELETE FROM {term_permissions_user} WHERE tid = %d", $form_state['values']['tid']);
  if (!empty($form_state['values']['access']['user'])) {
    $allowed_users = drupal_explode_tags($form_state['values']['access']['user']);
    foreach ($allowed_users as $name) {
      $u = user_load(array(
        'name' => $name,
      ));
      db_query("INSERT INTO {term_permissions_user} (tid, uid) VALUES (%d, %d)", $form_state['values']['tid'], $u->uid);
    }
  }

  // For each role, save the term ID and the role ID.
  db_query("DELETE FROM {term_permissions_role} WHERE tid = %d", $form_state['values']['tid']);
  if (!empty($form_state['values']['access']['role'])) {
    foreach (array_keys(array_filter($form_state['values']['access']['role'])) as $rid) {
      db_query("INSERT INTO {term_permissions_role} (tid, rid) VALUES (%d, %d)", $form_state['values']['tid'], $rid);
    }
  }
}