PHP 8.2 Warnings/Errors: Trying to access array offset on value of type null in menu_workbench_access_default_form_alter()

Created on 23 October 2024, about 2 months ago

Problem/Motivation

Hi, I'm maintaining a bunch of Drupal 7 sites that were moved to a recent Debian version (with PHP 8.2 installed) and I'm seeing a bunch of warnings/errors that need to be addressed:

Warning: Trying to access array offset on value of type null in menu_workbench_access_default_form_alter() (line 311 of /docroot/sites/all/modules/contrib/workbench_access/modules/menu.workbench_access.inc).

Warning: Trying to access array offset on value of type null in menu_workbench_access_default_form_alter() (line 313 of /docroot/sites/all/modules/contrib/workbench_access/modules/menu.workbench_access.inc).

Warning: foreach() argument must be of type array|object, null given in menu_workbench_access_default_form_alter() (line 313 of /docroot/sites/all/modules/contrib/workbench_access/modules/menu.workbench_access.inc).

Warning: Trying to access array offset on value of type null in menu_workbench_access_default_form_alter() (line 332 of /docroot/sites/all/modules/contrib/workbench_access/modules/menu.workbench_access.inc).

TypeError: array_key_exists(): Argument #2 ($array) must be of type array, null given in menu_workbench_access_default_form_alter() (line 332 of /docroot/sites/all/modules/contrib/workbench_access/modules/menu.workbench_access.inc).

Steps to reproduce

I'm trying to edit a page that has some special editorial access permissions and I'm getting these errors, not sure if they are related with the latest PHP 8.2 upgrade

Proposed resolution

Probably a patch is needed to address these issues.

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇨🇦Canada danrod Ottawa

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @danrod
  • 🇨🇦Canada danrod Ottawa

    Added a patch to fix this, the patch will check if $parent["#options"]) is empty or not (at the function menu_workbench_access_default_form_alter() ) and returns nothing if the array element doesn't exist or is empty:

    function menu_workbench_access_default_form_alter(&$form, &$form_state, $options) {
      if (!isset($form['menu'])) {
        return;
      }
    
      // If no options, then no access.
      if (empty($options)) {
        $form['menu']['#access'] = FALSE;
        return;
      }
    
      // Nothing to do if we're not limiting menu items.
      if (!variable_get('workbench_access_menu_limit', 1)) {
        return;
      }
    
      // Note that we require menu data for access control.
      $form['menu']['enabled']['#description'] = t('To enforce access control, this content must be placed in the menu.');
    
      // Adjust the parent form.
      $parent = &$form['menu']['link']['parent'];
    
      // No parent options are set return nothing for now
      if (!isset($parent["#options"]) && empty($parent["#options"])) {
        return;
      }
    ....
    
Production build 0.71.5 2024