- Issue created by @yurg
- Assigned to Sahana _N
- Status changed to Needs review
about 1 year ago 5:47am 23 October 2023 - 🇮🇳India sarwan_verma
Hi @yurg,
I have fixed this issue "Error: Call to a member function id() on null i" and also attached patch,
please review and verify. - Issue was unassigned.
- 🇸🇰Slovakia yurg
@sarwan_verma, @sahana _N thank you, there is one more place in the code to edit, it is at line 85 near the "(int) $user->id()":
if ((int) $user->id() !== (int) $node->getOwnerId() && !$node->isPublished()) { return FALSE; }
I'd also checked a few lines starting from the line 56:
if (empty($uid)) { $uid = \Drupal::currentUser()->id(); } $user = User::load($uid);
How about this (from https://api.drupal.org/api/drupal/core%21lib%21Drupal.php/function/Drupa...):
$user = \Drupal\user\Entity\User::load(\Drupal::currentUser() ->id());
Also we may want to handle anonymous users, e.g.
if ($uid === 0) // or if(isset($user))
- Assigned to marcoliver
- Merge request !373395700 - Check if user variable implements AccountInterface before using related methods → (Merged) created by marcoliver
- 🇩🇪Germany marcoliver Neuss, NRW, Germany
Hi @yurg, I created an Issue Fork & a merge request that go a bit further than what the patch in #4 does.
Basically we first check whether the
$user
variable implementsAccountInterface
, since all the methods we subsequently use are declared in that interface. If it is implemented, we proceed to the tests.Can you please check if the issue fork solves your problem?
- 🇸🇰Slovakia yurg
@marcoliver Thank you, have tried the patch with the latest Drupal 10.1.6 upgrade. Almost there, there is a block of code where empty $user throws an error, please see below:
- Error: Call to a member function getRoles() on null in Drupal\permissions_by_term\Service\AccessCheck->isAccessAllowedByDatabase() (line 165 of /permissions_by_term/src/Service/AccessCheck.php).
- Error: Call to a member function id() on null in Drupal\permissions_by_term\Service\AccessCheck->isAccessAllowedByDatabase() (line 175 of /permissions_by_term/src/Service/AccessCheck.php).
After wrapping
foreach ($user->getRoles() as $sUserRole) {
toif(!empty($user)) {
the issue is gone. Well, mostly: there is a lot ofThe 'entity:user' context is required and not present.
but I suppose it comes from somewhere else.
Thank you for all your help. - 🇩🇪Germany marcoliver Neuss, NRW, Germany
Hi yurg,
I've pushed some more changes to the issue fork. I hope the remaining two errors you experienced should now be gone as well. Can you please check again?
- 🇸🇰Slovakia yurg
@marcoliver
Thank you, it looks working with the most recent Version: 3.1.30 -
marcoliver →
committed 95f2bfa4 on 3.1.x-dev
Issue #3395700 by marcoliver, sarwan_verma, yurg: Error: Call to a...
-
marcoliver →
committed 95f2bfa4 on 3.1.x-dev
- Status changed to Fixed
11 months ago 2:03pm 15 January 2024 - 🇩🇪Germany marcoliver Neuss, NRW, Germany
Issue fork is merged. Will be released in 3.1.31.
Automatically closed - issue fixed for 2 weeks with no activity.