Commit 62292ec6 authored by Thomas Nilsson's avatar Thomas Nilsson
Browse files

Issue #3266427 by npcoder, sl27257: Call to a member function id() on null in...

Issue #3266427 by npcoder, sl27257: Call to a member function id() on null in line 24 of modules/contrib/flag_lists/src/Access/FlaggingCollectionAccessControlHandler.php
parent 45306afc
Loading
Loading
Loading
Loading
+20 −13
Original line number Diff line number Diff line
@@ -241,6 +241,7 @@ function flag_lists_flag_action_access($action, FlagInterface $flag, AccountInte
  $flagListsService = Drupal::service('flaglists');
  $flagLists = $flagListsService->getAllFlaggingCollections();
  foreach ($flagLists as $flagList) {
    // Check that the related Flag exists.
    if ($flagList->getRelatedFlag() !== NULL) {
      if ($flag->id() == $flagList->getRelatedFlag()->id()) {
        if ($flagList->getBaseFlag()->isGlobal()) {
@@ -354,13 +355,16 @@ function flag_lists_user_cancel($edit, UserInterface $account, $method) {
        $flagListsService->getUsersFlaggingCollections($account);
      // Reassign all Flagging Collections to uid 0.
      foreach ($flaggingCollections as $flaggingCollection) {
        // Check that the related Flag exists.
        if ($flaggingCollection->getRelatedFlag() !== NULL) {
          $flag_list_items = $flagListsService->getFlagListItemIds(
            $flaggingCollection->getRelatedFlag()->id());
          foreach ($flagListsService->getFlagListItems($flag_list_items)
            as $flag_list_item) {
            $flag_list_item->setOwnerId(0);
            $flag_list_item->save();
        };
          }
        }
        $flaggingCollection->setOwnerId(0);
        $flaggingCollection->save();
      }
@@ -378,12 +382,15 @@ function flag_lists_user_predelete($account) {
  $flaggingCollections =
    $flagListsService->getUsersFlaggingCollections($account);
  foreach ($flaggingCollections as $flaggingCollection) {
    // Check that the related Flag exists.
    if ($flaggingCollection->getRelatedFlag() !== NULL) {
      $flag_list_items = $flagListsService->getFlagListItemIds(
        $flaggingCollection->getRelatedFlag()->id());
      foreach ($flagListsService->getFlagListItems($flag_list_items)
        as $flag_list_item) {
        $flag_list_item->delete();
    };
      }
    }
    $flaggingCollection->delete();
  }
}