Problem/Motivation

A PHP notice is thrown when a new Invite type is created:

Notice: Trying to access array offset on value of type bool in Drupal\invite\Form\InviteTypeForm->form() (line 132 of modules/contrib/invite/src/Form/InviteTypeForm.php).
Drupal\invite\Form\InviteTypeForm->form(Array, Object) (Line: 106)
Drupal\Core\Entity\EntityForm->buildForm(Array, Object)
call_user_func_array(Array, Array) (Line: 531)
...

https://www.drupal.org/files/issues/2022-04-18/add-invite-notice.png

Steps to reproduce

  • Go to the page: Administration > Structure > Invite type > Add Invite type
    /admin/structure/invite_type/add
  • Check the Drupal error log. If you have errors set to display you should also see an error message on the screen.

Proposed resolution

The Notice is caused by this statement:

'#default_value' => $data['target_role'],

$data is not fully populated with values when a new invite_type entity is created.

The most straightforward fix is <?php '#default_value' => $data['target_role'] ?? '',

A patch to follow.

Comments

dale42 created an issue. See original summary.

dale42’s picture

Status: Active » Needs review
StatusFileSize
new552 bytes

The patch.

renatog’s picture

Status: Needs review » Reviewed & tested by the community

Totally agree. Really makes sense

  • RenatoG committed fcc68e1 on 8.x-1.x authored by dale42
    Issue #3275888 by dale42, RenatoG: Array offset error on Add Invite type...

  • RenatoG committed f17bf1d on 2.0.x authored by dale42
    Issue #3275888 by dale42, RenatoG: Array offset error on Add Invite type...
renatog’s picture

Status: Reviewed & tested by the community » Fixed

Moved to the dev branches 8.x-1.x and 2.0.x

Thank you so much for your great job @dale42

I'm testing the Hook Mail as well.

Status: Fixed » Closed (fixed)

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