- Issue created by @samaphp
- πΈπ¦Saudi Arabia samaphp Riyadh, SA πΈπ¦
The attached patch should add a default value for
$block_idto insure the variable will always be an array. - Status changed to Needs review
over 2 years ago 12:23pm 16 February 2023 - Status changed to Needs work
over 2 years ago 1:41pm 22 March 2023 - π«π·France vbouchet
Hi @samaphp.
As you mentioned, it is not possible to reproduce on a fresh install. Also, the $block_id is defined as a string, not as an array so if we really need to have a default value (which I am not sure), it should probably be a string instead. I feel if we need to fix something, it is probably more in BlockForm.php (providing the form displayed after clicking the "Place block" button) to add check somewhere (but not sure where as I don't reproduce).
- πͺπΈSpain alexahumada
Maybe issue 3351162 is related to this.
That issue can't be reproduced on a fresh install, you need at least one extra language set to default (in my case ES set as default language and EN as secondary) and it's not caused by other installed modules.
- π«π·France Grimreaper France π«π·
Hi,
I am also experiencing the error.
Patch from comment 2 is not the solution as otherwise the select field will be empty.
The problem comes from layout_builder_browser/src/Form/BlockForm.php:
$form['block_id'] = [ '#suffix' => '</div>', '#prefix' => '<div id="block-id-wrapper">', '#title' => $this->t('Block'), '#type' => 'select', '#options' => $blocks[$provider], '#default_value' => $browser_block->block_id, '#required' => TRUE, ];Initially $provider is empty so $blocks|$provider] is null, so fatal error in Select.php.
When wrapping in
if (!empty($provider) && isset($blocks[$provider])) {, then it is ok. The modal opens, but when choosing a provider, the ajax handling is not correct and the bug occurs again. - πͺπΈSpain alexahumada
grimreaper, take a look at https://www.drupal.org/project/layout_builder_browser/issues/3351162 π Undefined array key "" in Drupal\layout_builder_browser\Form\BlockForm Closed: duplicate , and try the patch I posted there, maybe it can solve your case temporarily until we find a better solution.
- π¨π·Costa Rica robert-arias
I am having the same issue, which only occurs when there are no custom blocks present.
What @Grimreaper in #6 says is correct, let me explain:
BlockForm.phptries to setInline blocksas the default provider, if found within the default providers; if not found, the provider will fallback to an empty string (''). The empty string makes the BlockSelectelement to fail.The
Selectelement fails because, when the provider is empty, the#optionsvalue will be empty (i.e., no blocks to select), and because we're just creating a newLayoutBuilderBrowserBlockentity, the#default_valuewill beNULL(i.e., thebrowser_block->block_idwill beNULL- no block has been selected to attach into the entity).Within Drupal, when a
Selectrender array is required and the#default_valueis empty (among other conditions), an#empty_valueis added to the render array to be merged with the#optionsvalues (that in this case, will beNULL). However, since no options were set due to an empty provider, PHP fails to merge an array with aNULLvalue, leading to the error.To solve this, I have set the provider to fallback to the first element of the
provider_optionsarray. This ensures that if there are no custom blocks, the first provider will be selected, and no error will be thrown because the provider exists and must have at least one block.Also, as explain on #4, the
LayoutBuilderBrowserBlock->blockIdmust be a string. While solution #2 may have worked, it is not ideal as theSelectelement thinks there is a#default_value, which skips the#empty_valueand#optionsmerge (besides changing the blockId type).#7 is a different issue and its solution does not work for this case.
- Status changed to Needs review
over 2 years ago 8:36pm 1 April 2023 - Status changed to RTBC
over 2 years ago 8:25am 3 April 2023 - π«π·France Grimreaper France π«π·
Hi,
Thanks @robert-arias.
Patch from comment 8 fixes the bug!
-
vbouchet β
committed 159675a7 on 8.x-1.x authored by
robert-arias β
Issue #3342348 by samaphp, robert-arias: Fails show the form of adding...
-
vbouchet β
committed 159675a7 on 8.x-1.x authored by
robert-arias β
- π«π·France vbouchet
Thanks for the patch and the testing. I was able to reproduce and confirm that the patch is fixing the issue. It will be part of the next release.
- Status changed to Fixed
over 2 years ago 3:24pm 20 April 2023 Automatically closed - issue fixed for 2 weeks with no activity.
- π«π·France vbouchet
This is a comment to see if @Grimreaper gets the credit he deserves for reviewing, suggesting correction and validating the patches in this issue.