Problem/Motivation
Error: Call to a member function getSection() on null in Drupal\layout_builder\Form\ConfigureBlockFormBase->getCurrentSection() (line 341 of /Applications/MAMP/htdocs/xxxxxx/docroot/core/modules/layout_builder/src/Form/ConfigureBlockFormBase.php).
Backtrace
#0 /Applications/MAMP/htdocs/xxxxx/docroot/core/modules/layout_builder/src/Form/ConfigureBlockFormBase.php(351): Drupal\layout_builder\Form\ConfigureBlockFormBase->getCurrentSection()
#1 /Applications/MAMP/htdocs/xxxxx/docroot/modules/contrib/layout_builder_styles/layout_builder_styles.module(22): Drupal\layout_builder\Form\ConfigureBlockFormBase->getCurrentComponent()
#2 /Applications/MAMP/htdocs/xxxxx/docroot/core/lib/Drupal/Core/Extension/ModuleHandler.php(545):
Steps to reproduce
Upgrade drupal 9.5.11 to 10.2.3
Go go layout builder and try to add any block under section we will get the above issue.
Proposed resolution
Need to find alternative way to get block plugin ID
$formObject = $formState->getFormObject();
$blockPluginId = $formObject
->getCurrentComponent()
->getPluginId();
$bundle = FALSE;
// If this is a reusable block, retrieve the block bundle.
if (strpos($blockPluginId, 'block_content:') === 0) {
$uuid = str_replace('block_content:', '', $blockPluginId);
$bundle = \Drupal::service('entity.repository')->loadEntityByUuid('block_content', $uuid)
->bundle();
}
Because in core addblockform updated in layout_builder.
Remaining tasks
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | 3423089-call_to_a_member_function_getSection_on_null_when_using_2999491.patch | 915 bytes | carolpettirossi |
| #6 | layout-builder-getsection-method-issue.patch | 605 bytes | kmani |
Comments
Comment #2
abhishek_gupta1 commentedComment #3
abhishek_gupta1 commentedComment #4
kgthompson commentedI am also having this issue on a D9->D10 upgraded site that heavily uses Layout Builder. I can't recreate it on a site that started as Drupal 10. Can you detail more on where your proposed changes would go?
Comment #5
bkosborneAre you patching core/layout builder? Your error message:
Error: Call to a member function getSection() on null in Drupal\layout_builder\Form\ConfigureBlockFormBase->getCurrentSection() (line 341 of /Applications/MAMP/htdocs/xxxxxx/docroot/core/modules/layout_builder/src/Form/ConfigureBlockFormBase.php).
There is no line 341 of ConfigureBlockFormBase in Drupal 10.2.x.
Comment #6
kmaniCurrently, i am patching the plugin id as empty as below
diff --git a/layout_builder_styles.module b/layout_builder_styles.module
index 99d83f1..c39d150 100644
--- a/layout_builder_styles.module
+++ b/layout_builder_styles.module
@@ -19,9 +19,7 @@ function layout_builder_styles_form_alter(&$form, FormStateInterface $formState)
/** @var \Drupal\layout_builder\Form\ConfigureBlockFormBase $formObject */
$formObject = $formState->getFormObject();
- $blockPluginId = $formObject
- ->getCurrentComponent()
- ->getPluginId();
+ $blockPluginId = "";
$bundle = FALSE;
// If this is a reusable block, retrieve the block bundle.
Comment #7
santhosh-kumar-rengasamy commentedPatch #6 worked for me.
Thanks @kmani
Comment #8
carolpettirossi commentedThe patch did not solve the issue for me. After I applied patch #6, I get a new error:
Backtrace:
Comment #9
carolpettirossi commentedI realized I was facing this issue because of the Reusable Block patch I applied related to https://www.drupal.org/project/drupal/issues/2999491.
Here's a patch to fix this issue when using Layout Builder Styles along with the Reusable Block patch.
Comment #10
eric.vvf commentedPatch #9 solved my problem! Thanks, @carolpettirossi.