function _tac_lite_user_tids in Taxonomy Access Control Lite 8
Same name and namespace in other branches
- 5 tac_lite.module \_tac_lite_user_tids()
- 6 tac_lite.module \_tac_lite_user_tids()
- 7 tac_lite.module \_tac_lite_user_tids()
Return the term ids of terms this user is allowed to access.
Users are granted access to terms either because of who they are, or because of the roles they have.
3 calls to _tac_lite_user_tids()
- tac_lite_create_form_alter in tac_lite_create/
tac_lite_create.module - Implements hook_form_alter().
- tac_lite_node_grants in ./
tac_lite.module - Implements hook_node_grants().
- tac_lite_query_term_access_alter in ./
tac_lite.module - Implements hook_query_TAG_alter().
File
- ./
tac_lite.module, line 177 - Control access to site content based on taxonomy, roles and users.
Code
function _tac_lite_user_tids($account, $scheme, $config) {
// Grant id 0 is reserved for nodes which were not given a grant id
// when they were created. By adding 0 to the grant id, we let the
// user view those nodes.
$grants = [
0,
];
$config = \Drupal::config('tac_lite.settings');
$schemes = $config
->get('tac_lite_schemes');
for ($i = 1; $i <= $schemes; $i++) {
$data = \Drupal::service('user.data')
->get('tac_lite', $account
->id(), 'tac_lite_scheme_' . $i) ?: [];
if (count($data)) {
foreach ($data as $tids) {
if (count($tids)) {
$grants = array_merge($grants, $tids);
}
}
}
}
// Add per-role grants in addition to per-user grants.
$settings = \Drupal::config('tac_lite.settings');
$defaults = $settings
->get('tac_lite_grants_scheme_' . $scheme);
$defaults = $defaults ? $defaults : [];
$roles = $account
->getRoles();
foreach ($roles as $rid) {
if (isset($defaults[$rid]) && count($defaults[$rid])) {
foreach ($defaults[$rid] as $tids) {
if (count($tids)) {
$grants = array_merge($grants, $tids);
}
}
}
}
// Because of some flakiness in the form API and the form we insert under
// user settings, we may have a bogus entry with vid set
// to ''. Here we make sure not to return that.
unset($grants['']);
return $grants;
}