Current Setup
Installation profile : Lightning.
Panels version: '8.x-4.3'
Landing page content type is configured to use panelizer. You can see the configuration in below snapshot.

Here are context settings for panelizer.

Steps to reproduce
Edit any draft node using panels in-place editor
• Click on Manage content
• Click on content to add a new field of 'landing page' content type.
• Add new field `Mobile Banner` in panels to display. Somethig like this

• Set it’s formatter to `rendered entity` with default display mode.

• Try to save it.
• It will throw errors in ajax call. We can see that in network tab of `inspect element`
Ajax errors are given below:
The website encountered an unexpected error. Please try again later.</br></br><em class="placeholder">Drupal\Component\Plugin\Exception\ContextException</em>: Required contexts without a value: entity. in <em class="placeholder">Drupal\Core\Plugin\Context\ContextHandler->applyContextMapping()</em> (line <em class="placeholder">96</em> of <em class="placeholder">core/lib/Drupal/Core/Plugin/Context/ContextHandler.php</em>). <pre class="backtrace">Drupal\panels_ipe\Form\PanelsIPEBlockPluginForm->buildBlockInstance(Object, Object) (Line: 298)
Drupal\panels_ipe\Form\PanelsIPEBlockPluginForm->submitForm(Array, Object, Object)
call_user_func_array(Array, Array) (Line: 69)
Drupal\Core\Form\FormAjaxResponseBuilder->buildResponse(Object, Array, Object, Array) (Line: 98)
Drupal\Core\Form\EventSubscriber\FormAjaxSubscriber->onException(Object, 'kernel.exception', Object)
call_user_func(Array, Object, 'kernel.exception', Object) (Line: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('kernel.exception', Object) (Line: 228)
Symfony\Component\HttpKernel\HttpKernel->handleException(Object, Object, 1) (Line: 79)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 67)
Drupal\simple_oauth\HttpMiddleware\BasicAuthSwap->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: 99)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 78)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 40)
Drupal\jsonapi\StackMiddleware\FormatSetter->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: 666)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
</pre>
Proposed resolution
Upon debugging I found that when i try to change field formatter from "Title" to "Rendered entity", Ajax call happens and form is saved in cache.
So next time when form is loaded from cache, $build_info is changed little bit.
"$panels_display" variable holds $context value as "@panelizer:entity_context:entity". Which is being unset when we save build info and retrieve from key value storage.
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | ipe-misses-contexts-after-layout-chnage-2989240-3.patch | 1.53 KB | afi13 |
| #2 | required-context-without-a-value-2989240-2.patch | 1.87 KB | mohit_aghera |
| Contexts__settings_panelizer.png | 151.86 KB | mohit_aghera | |
| Change_field_formatter.png | 117.63 KB | mohit_aghera | |
| Add_new_field.png | 104.42 KB | mohit_aghera |
Comments
Comment #2
mohit_aghera commentedThe attached patch is a quick workaround to set $panel_display's context variable based on setting object in session.
So drupal's form cache won't create any issue at all.
Another observation:
In "FormCache.php" file's
public function setCache($form_build_id, $form, FormStateInterface $form_state) {}method has approrpiate value of `$panel_display` variable i.e. with context value are set.When we try to retrieve values from
loadCachedFormState()method, `$panel_display->context` doesn't return anything. That will break buildForm method because context value is not present.Comment #3
afi13 commentedWe faced the same issue, but I guess session is not the best place for that. We can save context to temp store, same as it's done for display configuration.
Comment #4
afi13 commented