Hoping I didn't miss another open issue, using the D7 dev branch, I received the following error

Notice: Undefined offset: 4 in theme_nodeaccess_grants_form() (Zeile 836 von /Applications/XAMPP/xamppfiles/htdocs/drupal7.0/modules/nodeaccess/nodeaccess.module).
Notice: Undefined offset: 4 in nodeaccess_grants_form() (Zeile 577 von /Applications/XAMPP/xamppfiles/htdocs/drupal7.0/modules/nodeaccess/nodeaccess.module).
Notice: Undefined offset: 4 in nodeaccess_grants_form() (Zeile 577 von /Applications/XAMPP/xamppfiles/htdocs/drupal7.0/modules/nodeaccess/nodeaccess.module).

Seems to work nonetheless though...
(I was trying to add grants to newly added users.)
Great module! It saved me hours already!

CommentFileSizeAuthor
#4 undefined_offset_grants_form-1088920-4.patch541 bytesrv0

Comments

maxweld’s picture

I got a similar message. However, after I configured the module, specifically setting some "Allowed Roles" with the modules configuration page, this problem seemed to disappear.

tristanmatthews’s picture

So because it defaults to an array() in
$allowed_roles = variable_get('nodeaccess-roles', array());
the line
if (is_array($roles)) {
always returns true, so I just changed line 577 from
if ($allowed_roles[$key]) {
to
if (array_key_exists($key, $allowed_roles)) {
The problem goes away because once you have defined something your now longer loading the default empty array. I'm not really sure if this is the "proper solution" or has all the behavior desired but it made the error message go away for me so I'm going with it.

-Tristan

pdeclarens’s picture

Just for information !

I have the following:
Notice : Undefined offset: 1 dans nodeaccess_grants_form() (ligne 577 dans /homepages/42/d141549472/htdocs/mbc/drupal-7.4/sites/all/modules/nodeaccess/nodeaccess.module).
Notice : Undefined offset: 3 dans nodeaccess_grants_form() (ligne 577 dans /homepages/42/d141549472/htdocs/mbc/drupal-7.4/sites/all/modules/nodeaccess/nodeaccess.module).
Notice : Undefined offset: 2 dans nodeaccess_grants_form() (ligne 577 dans /homepages/42/d141549472/htdocs/mbc/drupal-7.4/sites/all/modules/nodeaccess/nodeaccess.module).

rv0’s picture

Status: Active » Needs review
StatusFileSize
new541 bytes

same as patch (with isset instead of array_key_exists as it is faster and more common used in drupal)

function nodeaccess_grants_form($form, &$form_state, $node) {
   if (is_array($roles)) {
     $form['rid'] = array('#tree' => TRUE);
     foreach ($roles as $key => $field) {
-      if ($allowed_roles[$key]) {
+      if (isset($allowed_roles[$key]) && $allowed_roles[$key]) {
         $form['rid'][$key]['name'] = array(
           '#type' => 'hidden',
           '#value' => $field['name'],
vlad.pavlovic’s picture

Thank you, will push the patch later today to dev version.

vlad.pavlovic’s picture

Status: Needs review » Fixed

Fix pushed to dev.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.