materio-d9/patches/hook_flag_access_id_on_null...

50 lines
2.0 KiB
Diff

diff --git a/flag_lists.module b/flag_lists.module
index cd81104..8a83435 100644
--- a/flag_lists.module
+++ b/flag_lists.module
@@ -240,23 +240,29 @@ function flag_lists_flag_action_access($action, FlagInterface $flag, AccountInte
$flagListsService = Drupal::service('flaglists');
$flagLists = $flagListsService->getAllFlaggingCollections();
foreach ($flagLists as $flagList) {
- if ($flag->id() == $flagList->getRelatedFlag()->id()) {
- if ($flagList->getBaseFlag()->isGlobal()) {
- // The flag list is global.
- return AccessResult::allowedIfHasPermission($account,
- 'access global flag lists');
- }
- elseif ($flagList->getOwnerId() == $account->id()) {
- // The flag list is owned by current user.
- return AccessResult::allowedIfHasPermission($account,
- 'view own flag lists');
- }
- else {
- // The user is allowed to see all flag lists.
- return AccessResult::allowedIfHasPermission($account,
- 'view flag lists');
+ if ($flagList->getRelatedFlag()) {
+ if ($flag->id() == $flagList->getRelatedFlag()->id()) {
+ if ($flagList->getBaseFlag()->isGlobal()) {
+ // The flag list is global.
+ return AccessResult::allowedIfHasPermission($account,
+ 'access global flag lists');
+ }
+ elseif ($flagList->getOwnerId() == $account->id()) {
+ // The flag list is owned by current user.
+ return AccessResult::allowedIfHasPermission($account,
+ 'view own flag lists');
+ }
+ else {
+ // The user is allowed to see all flag lists.
+ return AccessResult::allowedIfHasPermission($account,
+ 'view flag lists');
+ }
}
+ } else {
+ $logger = \Drupal::logger('flag_lists');
+ $logger->error('flagging_collection ' . $flagList->getName() . ' (' . $flagList->id() . ')' . ' owned by user id ' . $flagList->getOwner()->id() . ' doesn\'t have related flag');
}
+
}
// Check for access for the used template as well.