hook_flag_access_id_on_null.patch 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. diff --git a/flag_lists.module b/flag_lists.module
  2. index cd81104..3decec0 100644
  3. --- a/flag_lists.module
  4. +++ b/flag_lists.module
  5. @@ -237,47 +237,49 @@ function flag_lists_flag_action_access($action, FlagInterface $flag, AccountInte
  6. // Allow both users flag and the corresponding template.
  7. // Currently only the users flag lists are accepted.
  8. // This needs to corrected to allow also global lists.
  9. - $flagListsService = Drupal::service('flaglists');
  10. - $flagLists = $flagListsService->getAllFlaggingCollections();
  11. - foreach ($flagLists as $flagList) {
  12. - if ($flag->id() == $flagList->getRelatedFlag()->id()) {
  13. - if ($flagList->getBaseFlag()->isGlobal()) {
  14. - // The flag list is global.
  15. - return AccessResult::allowedIfHasPermission($account,
  16. - 'access global flag lists');
  17. - }
  18. - elseif ($flagList->getOwnerId() == $account->id()) {
  19. - // The flag list is owned by current user.
  20. - return AccessResult::allowedIfHasPermission($account,
  21. - 'view own flag lists');
  22. - }
  23. - else {
  24. - // The user is allowed to see all flag lists.
  25. - return AccessResult::allowedIfHasPermission($account,
  26. - 'view flag lists');
  27. + if ($flag){
  28. + $flagListsService = Drupal::service('flaglists');
  29. + $flagLists = $flagListsService->getAllFlaggingCollections();
  30. + foreach ($flagLists as $flagList) {
  31. + if ($flag->id() == $flagList->getRelatedFlag()->id()) {
  32. + if ($flagList->getBaseFlag()->isGlobal()) {
  33. + // The flag list is global.
  34. + return AccessResult::allowedIfHasPermission($account,
  35. + 'access global flag lists');
  36. + }
  37. + elseif ($flagList->getOwnerId() == $account->id()) {
  38. + // The flag list is owned by current user.
  39. + return AccessResult::allowedIfHasPermission($account,
  40. + 'view own flag lists');
  41. + }
  42. + else {
  43. + // The user is allowed to see all flag lists.
  44. + return AccessResult::allowedIfHasPermission($account,
  45. + 'view flag lists');
  46. + }
  47. }
  48. }
  49. - }
  50. -
  51. - // Check for access for the used template as well.
  52. - $flagTemplates = $flagListsService->getAllFlagForList();
  53. - foreach ($flagTemplates as $flagTemplate) {
  54. - if ($flag->id() == $flagTemplate->id()) {
  55. - // This is one of the template flags.
  56. - // But is it global?
  57. - $baseFlag = Drupal::service('flag')->getFlagById($flagTemplate->getBaseFlag());
  58. - if ($baseFlag->isGlobal()) {
  59. - return AccessResult::allowedIfHasPermission($account,
  60. - 'access global flag lists');
  61. - }
  62. - else {
  63. - return AccessResult::allowedIfHasPermissions($account, [
  64. - 'administer flag lists',
  65. - 'view own flag lists',
  66. - 'view flag lists',
  67. - ],
  68. - 'OR'
  69. - );
  70. +
  71. + // Check for access for the used template as well.
  72. + $flagTemplates = $flagListsService->getAllFlagForList();
  73. + foreach ($flagTemplates as $flagTemplate) {
  74. + if ($flag->id() == $flagTemplate->id()) {
  75. + // This is one of the template flags.
  76. + // But is it global?
  77. + $baseFlag = Drupal::service('flag')->getFlagById($flagTemplate->getBaseFlag());
  78. + if ($baseFlag->isGlobal()) {
  79. + return AccessResult::allowedIfHasPermission($account,
  80. + 'access global flag lists');
  81. + }
  82. + else {
  83. + return AccessResult::allowedIfHasPermissions($account, [
  84. + 'administer flag lists',
  85. + 'view own flag lists',
  86. + 'view flag lists',
  87. + ],
  88. + 'OR'
  89. + );
  90. + }
  91. }
  92. }
  93. }