Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
When using some other contrib modules I found the following error in some pages causing WSOD:
The website encountered an unexpected error. Please try again later.
Error: Call to a member function getThirdPartySetting() on null in block_class_preprocess_block() (line 38 of modules/contrib/block_class/block_class.module).
Here is the code of that particular function:
/**
* Implements hook_preprocess_HOOK().
*/
function block_class_preprocess_block(&$variables) {
// Blocks coming from page manager widget does not have id.
if (!empty($variables['elements']['#id'])) {
$block = Block::load($variables['elements']['#id']);
if ($classes = $block->getThirdPartySetting('block_class', 'classes')) { // line 38
$variables['attributes']['class'][] = $classes;
}
}
}
It looks that the $block
variable is null
.
Comment | File | Size | Author |
---|---|---|---|
#3 | call_to_a_member_function_on_null-2917683.patch | 606 bytes | Romixua |
#2 | 2917683-2-call-to-member-function-getThirdPartySetting.patch | 814 bytes | juankvillegas |
Comments
Comment #2
juankvillegas CreditAttribution: juankvillegas commentedHere is a patch that continues with the PHP logic only if the variable
$block
is notnull
.Comment #3
RomixuaI have this problem with block_field module.
Just need to check if $block not empty.
Comment #4
RomixuaComment #5
pookmish CreditAttribution: pookmish commentedJust ran into this yesterday and #3 patch works for me.
Comment #6
pookmish CreditAttribution: pookmish commentedComment #7
kybermanThank you for these patches. If possible, I would like to see patch #2 merged, because it's much more readable.
Comment #8
heshanlkWorking fine. Thanks
Comment #9
renatogAnd guys. I checked and really works good.
Comment #11
renatogCommitted to the dev branch.
Thank you all.
Best,