Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I am getting the following message on each page request when browsing as anonymous user.
Notice: Undefined index: anonymous in content_access_get_role_gid() (line 694 of modules/contrib/content_access/content_access.module).
Comment | File | Size | Author |
---|---|---|---|
#25 | content_access-role-2782813-25.patch | 484 bytes | gagelafleur |
| |||
#23 | content_access-role-2782813-23.patch | 483 bytes | gagelafleur |
#19 | content_access-role-2782813-19.patch | 478 bytes | mikhailkrainiuk |
#6 | content_access-role-2782813-6-D8.patch | 477 bytes | dsdeiz |
#4 | fix_undefined_index_anonymous_in_content_access_get_role_gid.patch | 1.87 KB | OlivierG |
Comments
Comment #2
acrosmanTry rebuilding the permissions. If that fails see #2719605: AJAX error when rebuilding permissions
Comment #3
roy_k CreditAttribution: roy_k commentedThis is what I see in the message and it mutiple:
I tried to rebuild the permissions and it didn`t do anything.
I will try to dig in deeper (and find a solution to it on the way) next week (unless someone else found a solution for it before I do).
Comment #4
OlivierG CreditAttribution: OlivierG as a volunteer commentedI did a patch for this. I don't know if it's correct but it's better without error...
Comment #5
smfmoreno CreditAttribution: smfmoreno commentedthank you, the patch #4 works for me!
Comment #6
dsdeiz CreditAttribution: dsdeiz at Promet Source commentedPatch doesn't seem to apply. I've attached the patch that applies.
Comment #7
dsdeiz CreditAttribution: dsdeiz at Promet Source commentedComment #8
LpSolit CreditAttribution: LpSolit as a volunteer commentedThis patch won't work as it now always returns NULL. (and it has a double ;; )
Comment #9
samalander CreditAttribution: samalander commented#4 patch worked for me as well. You just need to apply it from the drupal root rather than in the module's folder.
Comment #10
acrollet CreditAttribution: acrollet commentedThe patches are addressing a symptom rather than the root issue. The root issue is that the role GIDs are not properly populated. I worked around the issue on a site by re-running the code in content_access_install() - not sure why/how the anonymous GID was no longer saved in the config object though.
Comment #11
samalander CreditAttribution: samalander commentedThanks @acrollet (#10). I followed your advice and ran:
drush php:eval "require_once('modules/contrib/content_access/content_access.install');content_access_install();"
after reverting to the existing code and all the messages stopped.
Comment #12
superlolo95 CreditAttribution: superlolo95 commented+ 1 for the #10 and #11
Comment #13
jeremyH1024 CreditAttribution: jeremyH1024 commentedHaving this issue.
Tried #11 - The drush command 'php:eval require_once('modules/contrib/content_access/content_access.install');content_access_install();' could not be found. Run `drush cache-clear drush` to clear the commandfile [error]
cache if you have installed new extensions.
Tried clearing cache but same issue.
This is annoying. My customers are complaining.
Comment #14
Sardis CreditAttribution: Sardis at Drupalway, Drupal Ukraine Community, I-Next Ltd. for Drupal Ukraine Community, Drupalway, I-Next Ltd. commented#10 saved the day! Much appreciated!
Comment #15
nicolas-mosch CreditAttribution: nicolas-mosch commented#10 How exactly do I re-run the code in content_access_install()? I tried uninstalling the module and installing it again in the Drupal ui with no success.
Comment #16
Sardis CreditAttribution: Sardis at Drupalway, Drupal Ukraine Community, I-Next Ltd. for Drupal Ukraine Community, Drupalway, I-Next Ltd. commented@nicolas-mosch if you have drush installed you could use drush php-eval or drush core-cli.
Or you could enable devel module. It will have a route
devel/php
. There you'll see tex tarea for pasting the code fromcontent_access.install
Comment #17
Farnoosh CreditAttribution: Farnoosh commented#4 worked for me.
Comment #18
brooke_heaton CreditAttribution: brooke_heaton as a volunteer commented#4 worked for me.
Comment #19
mikhailkrainiuk CreditAttribution: mikhailkrainiuk as a volunteer and at DrupalJedi commentedHello!
#10 patch has syntax error -
$roles_gid
instead of$roles_gids
.It shows the message for me:
Added the fixed patch. Other logic works for me fine.
Comment #20
LpSolit CreditAttribution: LpSolit as a volunteer commentedAs I said in comment 8, you now always return NULL (+ a typo). This is not what we want, right? Comment 10 also disagrees with this fix.
Comment #21
mikhailkrainiuk CreditAttribution: mikhailkrainiuk as a volunteer and at DrupalJedi commentedAh, understood. Sorry.
Hm... Why we can't use ID's from the roles? (machine names)
Comment #22
brooke_heaton CreditAttribution: brooke_heaton as a volunteer commentedI attempted patch #19 and it removed the Notice however it resulted in a fatal error upon saving content:
"General error: 1366 Incorrect integer value: '' for column 'gid' at row 1: INSERT INTO {node_access}"
Comment #23
gagelafleur CreditAttribution: gagelafleur as a volunteer commentedThis is my first patch, so if I've done anything incorrectly please bear with me. I believe patch #19 just needed a return statement added to it.
Comment #24
gagelafleur CreditAttribution: gagelafleur as a volunteer commentedComment #25
gagelafleur CreditAttribution: gagelafleur as a volunteer commentedTrying this again. Still not sure if I'm doing something wrong, but I read into it more and created this version of the patch automatically via git diff.
Comment #26
gisleI believe this is not a bug, and that the patch is not needed. The solution is to make sure the module is properly installed - see comment #10.
I am unable to reproduce the behaviour reported in the issue summary. No notice appear on each page request when browsing as an anonymous user.
The notice reproduced in the issue summary says that the index 'anonymous' is undefined. The array in question is
$roles_gids
, and when I examine it on a newly installed Drupal 8.9.5 site, it has this contents:I.e. 'anonymous' it is not undefined if the module has been correctly installed.