You are here

function term_permissions_submit in Taxonomy Term Permissions 7

Same name and namespace in other branches
  1. 6 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
Implements hook_form_alter().

File

./term_permissions.module, line 229
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_delete('term_permissions_user')
    ->condition('tid', $form_state['values']['tid'])
    ->execute();
  if (!empty($form_state['values']['access']['user']) && $form_state['values']['op'] == t('Save')) {
    $allowed_users = drupal_explode_tags($form_state['values']['access']['user']);
    foreach ($allowed_users as $name) {
      $u = array_shift(user_load_multiple(array(), array(
        'name' => $name,
      )));
      $id = db_insert('term_permissions_user')
        ->fields(array(
        'tid' => $form_state['values']['tid'],
        'uid' => $u->uid,
      ))
        ->execute();
    }
  }

  // For each role, save the term ID and the role ID.
  db_delete('term_permissions_role')
    ->condition('tid', $form_state['values']['tid'])
    ->execute();
  if (!empty($form_state['values']['access']['role']) && $form_state['values']['op'] == t('Save')) {
    foreach (array_keys(array_filter($form_state['values']['access']['role'])) as $rid) {
      $id = db_insert('term_permissions_role')
        ->fields(array(
        'tid' => $form_state['values']['tid'],
        'rid' => $rid,
      ))
        ->execute();
    }
  }
}