function permissions_by_term_submit in Permissions by Term 7
Same name and namespace in other branches
- 8.2 permissions_by_term.module \permissions_by_term_submit()
- 8 permissions_by_term.module \permissions_by_term_submit()
Submit handler for permissions_by_term_form_alter().
1 string reference to 'permissions_by_term_submit'
File
- ./
permissions_by_term.module, line 230 - Allows access to terms in a vocabulary to be limited by user or role.
Code
function permissions_by_term_submit($form, &$form_state) {
// For each user, save the term ID and the user ID.
db_delete('permissions_by_term_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']);
$query = db_insert('permissions_by_term_user')
->fields(array(
'tid',
'uid',
));
foreach ($allowed_users as $name) {
$user = db_query("SELECT u.uid FROM {users} u WHERE u.name = :uname", array(
':uname' => $name,
))
->fetchCol();
$query
->values(array(
'tid' => $form_state['values']['tid'],
'uid' => $user['0'],
));
}
$query
->execute();
}
// For each role, save the term ID and the role ID.
db_delete('permissions_by_term_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) {
db_insert('permissions_by_term_role')
->fields(array(
'tid' => $form_state['values']['tid'],
'rid' => $rid,
))
->execute();
}
}
}