Call to a member function getSection() on null

Created on 22 February 2024, 10 months ago
Updated 18 September 2024, 3 months ago

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

🐛 Bug report
Status

Active

Version

2.0

Component

Code

Created by

🇮🇳India kmani

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @kmani
  • Assigned to abhishek_virasat
  • Issue was unassigned.
  • 🇺🇸United States kgthompson

    I 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?

  • 🇺🇸United States bkosborne New Jersey, USA

    Are 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.

  • 🇮🇳India kmani

    Currently, 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.

  • Patch #6 worked for me.
    Thanks @kmani

  • 🇧🇷Brazil carolpettirossi Campinas - SP

    The patch did not solve the issue for me. After I applied patch #6, I get a new error:

    Error: Call to a member function getSection() on null in Drupal\layout_builder\Form\ConfigureBlockFormBase->getCurrentSection() (line 343 of /var/www/web/core/modules/layout_builder/src/Form/ConfigureBlockFormBase.php).
    

    Backtrace:

    #0 /var/www/web/core/modules/layout_builder/src/Form/ConfigureBlockFormBase.php(353): Drupal\layout_builder\Form\ConfigureBlockFormBase->getCurrentSection()
    #1 /var/www/web/modules/contrib/layout_builder_styles/layout_builder_styles.module(50): Drupal\layout_builder\Form\ConfigureBlockFormBase->getCurrentComponent()
    #2 /var/www/web/core/lib/Drupal/Core/Extension/ModuleHandler.php(552): layout_builder_styles_form_alter(Array, Object(Drupal\Core\Form\FormState), 'layout_builder_...')
    #3 /var/www/web/core/lib/Drupal/Core/Form/FormBuilder.php(834): Drupal\Core\Extension\ModuleHandler->alter('form', Array, Object(Drupal\Core\Form\FormState), 'layout_builder_...')
    #4 /var/www/web/core/lib/Drupal/Core/Form/FormBuilder.php(285): Drupal\Core\Form\FormBuilder->prepareForm('layout_builder_...', Array, Object(Drupal\Core\Form\FormState))
    #5 /var/www/web/core/lib/Drupal/Core/Controller/FormController.php(73): Drupal\Core\Form\FormBuilder->buildForm(Object(Drupal\layout_builder\Form\AddBlockForm), Object(Drupal\Core\Form\FormState))
    #6 [internal function]: Drupal\Core\Controller\FormController->getContentResult(Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Routing\RouteMatch))
    #7 /var/www/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array)
    #8 /var/www/web/core/lib/Drupal/Core/Render/Renderer.php(638): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
    #9 /var/www/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(121): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))
    #10 /var/www/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array)
    #11 /var/www/vendor/symfony/http-kernel/HttpKernel.php(181): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
    #12 /var/www/vendor/symfony/http-kernel/HttpKernel.php(76): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)
    #13 /var/www/web/core/lib/Drupal/Core/StackMiddleware/Session.php(53): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #14 /var/www/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #15 /var/www/web/core/lib/Drupal/Core/StackMiddleware/ContentLength.php(28): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #16 /var/www/web/core/modules/big_pipe/src/StackMiddleware/ContentLength.php(32): Drupal\Core\StackMiddleware\ContentLength->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #17 /var/www/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\big_pipe\StackMiddleware\ContentLength->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #18 /var/www/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #19 /var/www/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #20 /var/www/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #21 /var/www/web/core/lib/Drupal/Core/StackMiddleware/AjaxPageState.php(36): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #22 /var/www/web/core/lib/Drupal/Core/StackMiddleware/StackedHttpKernel.php(51): Drupal\Core\StackMiddleware\AjaxPageState->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #23 /var/www/web/core/lib/Drupal/Core/DrupalKernel.php(741): Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #24 /var/www/web/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request))
    #25 {main}
    
  • 🇧🇷Brazil carolpettirossi Campinas - SP

    I realized I was facing this issue because of the Reusable Block patch I applied related to https://www.drupal.org/project/drupal/issues/2999491 Add reusable option to inline block creation Needs review .

    Here's a patch to fix this issue when using Layout Builder Styles along with the Reusable Block patch.

  • Patch #9 solved my problem! Thanks, @carolpettirossi.

Production build 0.71.5 2024