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.
Landing page panelizer configuration

Here are context settings for panelizer.
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
Add new field using panels in place editor

• Set it’s formatter to `rendered entity` with default display mode.
Change field formatter to rendered entity
• 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-&gt;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-&gt;buildBlockInstance(Object, Object) (Line: 298)
Drupal\panels_ipe\Form\PanelsIPEBlockPluginForm-&gt;submitForm(Array, Object, Object)
call_user_func_array(Array, Array) (Line: 69)
Drupal\Core\Form\FormAjaxResponseBuilder-&gt;buildResponse(Object, Array, Object, Array) (Line: 98)
Drupal\Core\Form\EventSubscriber\FormAjaxSubscriber-&gt;onException(Object, &#039;kernel.exception&#039;, Object)
call_user_func(Array, Object, &#039;kernel.exception&#039;, Object) (Line: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher-&gt;dispatch(&#039;kernel.exception&#039;, Object) (Line: 228)
Symfony\Component\HttpKernel\HttpKernel-&gt;handleException(Object, Object, 1) (Line: 79)
Symfony\Component\HttpKernel\HttpKernel-&gt;handle(Object, 1, 1) (Line: 67)
Drupal\simple_oauth\HttpMiddleware\BasicAuthSwap-&gt;handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session-&gt;handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle-&gt;handle(Object, 1, 1) (Line: 99)
Drupal\page_cache\StackMiddleware\PageCache-&gt;pass(Object, 1, 1) (Line: 78)
Drupal\page_cache\StackMiddleware\PageCache-&gt;handle(Object, 1, 1) (Line: 40)
Drupal\jsonapi\StackMiddleware\FormatSetter-&gt;handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware-&gt;handle(Object, 1, 1) (Line: 52)
Drupal\Core\StackMiddleware\NegotiationMiddleware-&gt;handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel-&gt;handle(Object, 1, 1) (Line: 666)
Drupal\Core\DrupalKernel-&gt;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.

Comments

mohit_aghera created an issue. See original summary.

mohit_aghera’s picture

Status: Active » Needs work
StatusFileSize
new1.87 KB

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

afi13’s picture

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

afi13’s picture

Status: Needs work » Needs review

The last submitted patch, 2: required-context-without-a-value-2989240-2.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Status: Needs review » Needs work

The last submitted patch, 3: ipe-misses-contexts-after-layout-chnage-2989240-3.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.