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
Comment #2
pooja_sharma commentedVerified 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.
Comment #3
dydave commentedI have tested this with the latest 4.0.x-dev version and was unable to reproduce the issue.
Tested with:
I tried:
/admin/config/content/block-class/class-list./admin/config/content/block-class/class-list./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_storednow seems to be properly typed (schema) and initialized (install)...The
ifblock 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!