Problem/Motivation

There is an error after save

Mensaje de error
Close
Notice: Trying to access array offset on value of type null in Drupal\Core\Menu\Plugin\Block\LocalTasksBlock->blockSubmit() (line 153 of core/lib/Drupal/Core/Menu/Plugin/Block/LocalTasksBlock.php).
Drupal\Core\Menu\Plugin\Block\LocalTasksBlock->blockSubmit(Array, Object) (Line: 227)
Drupal\Core\Block\BlockBase->submitConfigurationForm(Array, Object) (Line: 750)
Drupal\context\Plugin\ContextReaction\Blocks->submitConfigurationForm(Array, Object) (Line: 207)
Drupal\context_ui\Form\ContextFormBase->handleReactions(Array, Object) (Line: 150)
Drupal\context_ui\Form\ContextFormBase->submitForm(Array, Object)
call_user_func_array(Array, Array) (Line: 113)
Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object) (Line: 51)
Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object) (Line: 593)
Drupal\Core\Form\FormBuilder->processForm('context_edit_form', Array, Object) (Line: 144)
Drupal\autosave_form\Form\AutosaveFormBuilder->processForm('context_edit_form', Array, Object) (Line: 321)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 97)
Drupal\autosave_form\Form\AutosaveFormBuilder->buildForm(Object, Object) (Line: 73)
Drupal\Core\Controller\FormController->getContentResult(Object, Object) (Line: 39)
Drupal\layout_builder\Controller\LayoutBuilderHtmlEntityFormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 573)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 158)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 80)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 52)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 706)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Steps to reproduce

  1. Create a new context
  2. Add a block
  3. Save
  4. Edit the context
  5. Move the block to another region
  6. Click on Save and Continue

Core 9.1.10

Comments

Freddy Rodriguez created an issue. See original summary.

paulocs’s picture

Version: 8.x-4.0-beta6 » 8.x-4.x-dev
Status: Active » Postponed (maintainer needs more info)

I couldn't reproduce the error with the steps provided...
Can you give more details how to reproduce the error?

hygglo’s picture

I have also ran in to this issue. By removing one block at the time I've traced it down to the "Tabs" block from core.

Will post here again if I find a solution.

hygglo’s picture

ok, I've made it a big further.

If you have a "Tabs" block and saving it

core/lib/Drupal/Core/Menu/Plugin/Block/LocalTasksBlock.php

  /**
   * {@inheritdoc}
   */
  public function blockSubmit($form, FormStateInterface $form_state) {
    $levels = $form_state->getValue('levels');
    $this->configuration['primary'] = $levels['primary'];
    $this->configuration['secondary'] = $levels['secondary'];
  }

Is triggered.

I'm not sure why as it doesn't make sense for it to be executed. Its then looking for

$form_state->getValue('levels');

But as that field is not in the form(it is in the Tabs form) the gives an error.

paulocs’s picture

Status: Postponed (maintainer needs more info) » Active
mistergroove’s picture

I get a similar error with SystemBranding block when I save in Drupal 9.3.8 and 8.9.20... Seems related.

Warning: Trying to access array offset on value of type null in Drupal\system\Plugin\Block\SystemBrandingBlock->blockSubmit() (line 142 of core/modules/system/src/Plugin/Block/SystemBrandingBlock.php).
Warning: Trying to access array offset on value of type null in Drupal\system\Plugin\Block\SystemBrandingBlock->blockSubmit() (line 143 of core/modules/system/src/Plugin/Block/SystemBrandingBlock.php).
Warning: Trying to access array offset on value of type null in Drupal\system\Plugin\Block\SystemBrandingBlock->blockSubmit() (line 144 of core/modules/system/src/Plugin/Block/SystemBrandingBlock.php).

The line numbers slightly change between versions but the error is the same.

Seems to be the same issue as @Hygglo describes with the Tabs issue... The 'getValue' doesnt get the relevant values for the config as we are not saving the individual block configuration when the context is saved if I'm not mistaken.

  /**
   * {@inheritdoc}
   */
  public function blockSubmit($form, FormStateInterface $form_state) {
    $block_branding = $form_state->getValue('block_branding');
    $this->configuration['use_site_logo'] = $block_branding['use_site_logo'];
    $this->configuration['use_site_name'] = $block_branding['use_site_name'];
    $this->configuration['use_site_slogan'] = $block_branding['use_site_slogan'];
  }
jsidigital’s picture

I also get this with the tabs.
Was any solution or patch found for this?

Anonymous’s picture

Hello,

I've been trying to replicate this issue to try to resolve, but with following the steps provided in the issue summary I was unable to do so. Could you please provide more information about your issue: How did you setup the context (what conditions and reactions you're using), which theme is being used when this error occurs, are there any other modules or custom code used that interact with the blocks you've encountered this issue at?

For testing I've been using:
Drupal 9.3.8 Php 8.0
Drupal 9.5.x-dev Php 8.1
In both cases I've used the current latest development version of this module 4.x-dev (commit 86f2ca41)

aimevp’s picture

Priority: Normal » Major

I'm having the issue as well with following specs:

Drupal: 9.4.5
PHP: 7.4.30
Context: 8.x-4.1

It's happening on 2 custom themes. So I'm not convinced this is theme dependent.
The site was created with a custom install profile where the context was already predefined.

Condition: request-path with * as "pages" value => so all pages
Reaction: blocks

When I create a new context with only a user account menu block there is no problem.
Once I add the System Branding Block in a region for example, there errors appear.

So this has definitly something to do with form_state values core is expecting when invoking the blockSubmit() methods of those core blocks where core is expecting "block_branding", "levels", etc and context isn't providing it.

igork96’s picture

I tried to reproduce this using Drupal: 9.4.8, PHP: 7.4.30 and Context: 8.x-4.1 but I can't... Can you please try this maybe on a fresh install of Drupal and describe the precise steps and versions to reproduce it?

aimevp’s picture

I finally got around it to do some more testing to find out why some didn't see the issue others experienced and found the difference.

I did a clean install of Drupal 9.4.8 in combination with only context 4.1.0. These are the steps to reproduce the error:

- Install using minimal or standard profile
- Enable all messages and errors at "admin/config/development/logging"
- In case of minimal profile place the "messages" block
- Create a new context (condition: request path with value *, reaction blocks and place "site branding" for example in a region)
- Save the context
- You should see the errors.

I think the big difference was that Drupal out of the box doesn't show error messages. because in my first attempt I also couldn't reproduce it until I finally thought about the error reporting.

freddy rodriguez’s picture

StatusFileSize
new359.33 KB

jernejmramor

This is the context config.

freddy rodriguez’s picture

StatusFileSize
new547.65 KB
pdxclankeith’s picture

I've run into this same problem on Drupal 10.1.5 and Context 5.0.0-rc1. Has there been any movement on getting a fix/patch for this?

Error message is for the SystemBrandingBlock:

Warning: Trying to access array offset on value of type null in Drupal\system\Plugin\Block\SystemBrandingBlock->blockSubmit() (line 142 of core/modules/system/src/Plugin/Block/SystemBrandingBlock.php).
Drupal\system\Plugin\Block\SystemBrandingBlock->blockSubmit(Array, Object) (Line: 234)
Drupal\Core\Block\BlockBase->submitConfigurationForm(Array, Object) (Line: 756)
Drupal\context\Plugin\ContextReaction\Blocks->submitConfigurationForm(Array, Object) (Line: 207)
Drupal\context_ui\Form\ContextFormBase->handleReactions(Array, Object) (Line: 150)
Drupal\context_ui\Form\ContextFormBase->submitForm(Array, Object)
call_user_func_array(Array, Array) (Line: 114)
Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object) (Line: 52)
Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object) (Line: 597)
Drupal\Core\Form\FormBuilder->processForm('context_edit_form', Array, Object) (Line: 325)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 73)
Drupal\Core\Controller\FormController->getContentResult(Object, Object) (Line: 39)
Drupal\layout_builder\Controller\LayoutBuilderHtmlEntityFormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 617)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 182)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 704)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
mistergroove’s picture

This issue still consistently exists for me on both 8.x-4.x and 5.0.0-rc1 on drupal 9.

Warning: Trying to access array offset on value of type null in Drupal\system\Plugin\Block\SystemBrandingBlock->blockSubmit() (line 142 of core/modules/system/src/Plugin/Block/SystemBrandingBlock.php).
Warning: Trying to access array offset on value of type null in Drupal\system\Plugin\Block\SystemBrandingBlock->blockSubmit() (line 143 of core/modules/system/src/Plugin/Block/SystemBrandingBlock.php).
Warning: Trying to access array offset on value of type null in Drupal\system\Plugin\Block\SystemBrandingBlock->blockSubmit() (line 144 of core/modules/system/src/Plugin/Block/SystemBrandingBlock.php).

To get the error add a system branding block to a context, save, update that block through context , and then click "save and continue" or "save and exit" on the context edit page.

cslevy’s picture

This will happen for all Blocks, that has a hierarchical structure in the form.

$block_state = (new FormState())->setValues($configuration);
$block->submitConfigurationForm($form, $block_state);

Here the FormState is initialised with the $configuration values which is a simple array, but if you check the SystemBrandingBlock or LocalTasksBlock blockSubmits, you can see that the values from the fieldset are moved to the top level values.

So this is a general issue, and will show up for every block which has hierarchical form structure.

aronne’s picture

StatusFileSize
new644 bytes

Hi,
there's an error in the default configurations. Values were set wrong.
Attached patch.