Problem/Motivation

Warning: foreach() argument must be of type array|object, null given in /app/htdocs/modules/contrib/block_class/src/Controller/BlockClassController.php on line 282

Steps to reproduce

Drupal version 10.1.1
The above error is displayed when you visit this page
admin/config/content/block-class/class-list

Proposed resolution

Move the foreach() into an if statement

if ($block_classes_stored != NULL) {
      // Get the array values and id in the keys.
      $block_classes_stored = array_values($block_classes_stored);


      foreach ($block_classes_stored as $block_class) {

        $table .= '<tr>';
        $table .= '<td>' . $block_class . '</td>';
        $table .= '</tr>';

      }
    }

Remaining tasks

User interface changes

API changes

Data model changes

Comments

richardhobbs created an issue. See original summary.

pooja_sharma’s picture

Status: Active » Reviewed & tested by the community
StatusFileSize
new68.76 KB
new34.58 KB
new40.59 KB

Verified and tested the block-class.patch on 2.0.11 , warning is fixable by adding patch. Added screenshot for reference.

Can be moved to RTBC+1.

dydave’s picture

Status: Reviewed & tested by the community » Closed (outdated)

I have tested this with the latest 4.0.x-dev version and was unable to reproduce the issue.
Tested with:

  • drupal/core: 11.2.5
  • block_class: 4.0.x-dev
  • PHP: 8.3

 
I tried:

  • Enabling the module and browsing directly to /admin/config/content/block-class/class-list.
  • Creating classes and browsing directly to /admin/config/content/block-class/class-list.
  • Removing all classes (bulk remove) and browsing directly to /admin/config/content/block-class/class-list.

 
and was unable to reproduce the error/warning message described in the issue summary.

Besides, looking at the code, the patch now seems to be a bit outdated, since the variable block_classes_stored now seems to be properly typed (schema) and initialized (install)...
The if block around the code in the patch, seems to have been removed... 🤔

Could you please try updating and testing the issue again with the latest version of the module and see if the issue still occurs?

For now, marking as Closed (outdated), but feel free to re-open this issue, or create a new one if you still encounter the same problem with the latest versions of the module.

Feel free to let us know if you would have any questions or concerns on any aspects of the latest code changes or the module in general, we would surely be glad to hear your feedback. 😊
Thanks in advance!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.