On "Add simple block page" (/admin/structure/block/simple-block/add)
I get the following 2 warnings:
Notice: Trying to access array offset on value of type null in Drupal\simple_block\SimpleBlockEditForm->form() (line 54 of modules/contrib/simple_block/src/SimpleBlockEditForm.php).
Notice: Trying to access array offset on value of type null in Drupal\simple_block\SimpleBlockEditForm->form() (line 56 of modules/contrib/simple_block/src/SimpleBlockEditForm.php).
The problematic lines are these 2:
Line 54: '#format' => $simple_block->getContent()['format'],
Line 56: '#default_value' => $simple_block->getContent()['value'],
And this is happening because when creating a new block, the function "getContent()" returns Null.
A possible solution would be replacing the above lines these with
$simple_block_content = $simple_block->getContent();
'#format' => $simple_block_content ? $simple_block_content['format'] : '',
'#default_value' => $simple_block_content ? $simple_block_content['value'] : '',
(I'm on PHP 7.4 & Drupal 9 btw)
Issue fork simple_block-3195886
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
zekvyrin commentedComment #4
zekvyrin commentedI created a merge request for this issue.
Comment #5
zekvyrin commentedComment #6
dsnopekI also encountered this problem, and the patch fixed it for me!
Comment #7
vipin.mittal18Thanks for the patch. I applied at one of my containers and working perfectly.
RTBC +1
Comment #8
poorva commentedthis patch worked for me +1
Comment #9
chi commentedThe patch resolves the notice. However it does not fix the root cause of the problem.
SimpleBlock::getContent()should always return array as declared in its interface.Comment #13
zekvyrin commentedI'm sorry please ignore merge request !3 (it's something for another issue and I accidentally using a wrong fork).
@Chi is right, this wasn't compatible with the documentation. I created a new merge request (!5) that returns an empty array instead.
Also has a better result in the end, because now the default format is the first available format for the user.
Comment #14
zekvyrin commentedComment #15
zekvyrin commentedComment #17
claudiu.cristeaWhy not just doing this?
Comment #18
chi commented@Zekvyrin, Drupal core 8.x still supports PHP 7.0. Given that this module does not specify PHP requirements, users will expect it to work on any PHP versions that are supported by Drupal core.
Contributed modules do not have to support same PHP versions as Drupal core. But this needs to be declared explicitly in composer.json file and in module info file. This would block installing a module on unsupported platforms and make users less confused.
Comment #20
claudiu.cristeaComment #21
claudiu.cristeaThanks you. Fixed.