diff --git a/tac_lite.module b/tac_lite.module index 5ce5e1a..fe487f7 100644 --- a/tac_lite.module +++ b/tac_lite.module @@ -181,25 +181,29 @@ function _tac_lite_user_tids($account, $scheme) { // when they were created. By adding 0 to the grant id, we let the // user view those nodes. $grants = [0]; - $data = \Drupal::service('user.data')->get('tac_lite', $account->id(), 'tac_lite_scheme_' . $scheme) ?: []; - if (count($data)) { - foreach ($data as $tids) { - if (count($tids)) { - $grants = array_merge($grants, $tids); + if ($account->id() != NULL) { + $data = \Drupal::service('user.data')->get('tac_lite', $account->id(), 'tac_lite_scheme_' . $scheme) ?: []; + 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); + if ($account->id() != NULL) { + $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); + } } } }