Hi all!
I have a weird behaviour in the latest site I have updated to the latest version.
After updating to bootstrap 8.x-3.19, in this site, if I go to /user/register I get the following error
The website encountered an unexpected error. Please try again later.
In the logs, the error I get says the following:
Error: Call to a member function id() on null in Drupal\bootstrap\Bootstrap::isAdmin() (line 1247 of .../web/themes/contrib/bootstrap/src/Bootstrap.php) #0 .../web/themes/contrib/bootstrap/src/Bootstrap.php(1373): Drupal\bootstrap\Bootstrap::isAdmin() #1......
In the line of the error we can find
...
(1246) $user = $user ?: User::load(\Drupal::currentUser()->id());
(1247) $uid = (int) $user->id();
...
If we check the drupal documentation (https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Entity%21...), if the user is anonymous (well, he is going to create a new account...), then the User::load returns null and the next line is the one that fails as the $user var is null.
Shouldn't be a check to see if $user is null and return false before checking the id() part?
Comment | File | Size | Author |
---|---|---|---|
#7 | 3057674-7.patch | 2.09 KB | markhalliwell |
Comments
Comment #2
gorkagr CreditAttribution: gorkagr at Erasmus Student Network commentedAfter testing a bit in the morning, i can say that checking if the $user exists or not and returning false fixes this small issue.
No idea why is this happening only in one site and not in the others (can be a combination of modules used most likely in the one failing)
Here is a simple patch that works for me and allows the users to register in my site.
Comment #3
markhalliwellThis change doesn't make sense.
$user ? $user
is redundant because that is what?:
is for: assigns the$user
object if it exists, otherwise it loads the current user.Should be
FALSE
. Also, I'd add some blank lines around the if statement block here with a comment above it explaining when this condition can occur.Comment #4
gorkagr CreditAttribution: gorkagr at Erasmus Student Network commentedhi!
Thnks for the reply.
I didnt know you could ommit the first part in the ?: (i was always adding it).
I have changed the false and added a comment before. Check if it is ok.
Comment #5
geffio CreditAttribution: geffio commentedI was having this issue with one site I'm working on, and can confirm #4 this fixes it for me.
Thanks!
Comment #6
markhalliwellActually, I think we can go a different route altogether that will make more sense, logically.
Comment #7
markhalliwellPlease test this patch instead. It avoids
User::load()
altogether and will instead, ultimately, use\Drupal\Core\Session\AnonymousUserSession
for anonymous users. Thus, allowing us to always have some sort of object that will return an ID.Comment #8
gorkagr CreditAttribution: gorkagr at Erasmus Student Network commentedJust tested #7.
Works fine and no issues when requesting the page.
Not related, but i have just noticed some issues with the CSS (images) loaded via the jsdelivr.net
Comment #11
markhalliwell