Problem/Motivation
Dale Moore got this error:
The website encountered an unexpected error. Try again later.
Drupal\Component\Plugin\Exception\ContextException: The 'entity:paragraph' context is required and not present. in Drupal\Core\Plugin\Context\Context->getContextValue() (line 73 of core/lib/Drupal/Core/Plugin/Context/Context.php).
Drupal\ui_patterns\Plugin\UiPatterns\DerivableContext\EntityReferencedDerivableContext->getDerivedContexts() (Line: 124)
Drupal\ui_patterns\Plugin\UiPatterns\Source\DerivableContextSourceBase->getSourcePlugins() (Line: 95)
Drupal\ui_patterns\Plugin\UiPatterns\Source\DerivableContextSourceBase->getPropValue() (Line: 199)
Drupal\ui_patterns\SourcePluginBase->getValue() (Line: 87)
Drupal\ui_patterns\Element\ComponentElementBuilder->buildProp() (Line: 68)
Drupal\ui_patterns\Element\ComponentElementBuilder->buildProps() (Line: 49)
Drupal\ui_patterns\Element\ComponentElementBuilder->build()
call_user_func_array() (Line: 113)
Drupal\Core\Render\Renderer->doTrustedCallback() (Line: 870)
Drupal\Core\Render\Renderer->doCallback() (Line: 432)
Drupal\Core\Render\Renderer->doRender() (Line: 248)
Drupal\Core\Render\Renderer->render() (Line: 484)
Drupal\Core\Template\TwigExtension->escapeFilter() (Line: 44)
__TwigTemplate_cde85cbeced03ad7304f0b171ffab65b->doDisplay() (Line: 387)
Twig\Template->yield() (Line: 343)
Twig\Template->display() (Line: 358)
Twig\Template->render() (Line: 35)
Twig\TemplateWrapper->render() (Line: 33)
twig_render_template() (Line: 348)
Drupal\Core\Theme\ThemeManager->render() (Line: 491)
Drupal\Core\Render\Renderer->doRender() (Line: 248)
Drupal\Core\Render\Renderer->render() (Line: 484)
Drupal\Core\Template\TwigExtension->escapeFilter() (Line: 244)
__TwigTemplate_f8bf2811b71e722f6934d6c00224e74b->{closure}() (Line: 2058)
Twig\Extension\CoreExtension::captureOutput() (Line: 213)
__TwigTemplate_f8bf2811b71e722f6934d6c00224e74b->macro_content() (Line: 191)
__TwigTemplate_f8bf2811b71e722f6934d6c00224e74b->{closure}() (Line: 2058)
Twig\Extension\CoreExtension::captureOutput() (Line: 119)
__TwigTemplate_f8bf2811b71e722f6934d6c00224e74b->macro_field() (Line: 87)
__TwigTemplate_f8bf2811b71e722f6934d6c00224e74b->doDisplay() (Line: 387)
Twig\Template->yield() (Line: 343)
Twig\Template->display() (Line: 358)
Twig\Template->render() (Line: 35)
Twig\TemplateWrapper->render() (Line: 33)
twig_render_template() (Line: 348)
Drupal\Core\Theme\ThemeManager->render() (Line: 491)
Drupal\Core\Render\Renderer->doRender() (Line: 504)
Drupal\Core\Render\Renderer->doRender() (Line: 248)
Drupal\Core\Render\Renderer->render() (Line: 484)
Drupal\Core\Template\TwigExtension->escapeFilter() (Line: 86)
__TwigTemplate_99eb390ab14c963e3444974959882998->doDisplay() (Line: 387)
Twig\Template->yield() (Line: 141)
__TwigTemplate_954931822877dc81be93f06e93d55692___1923388244->doDisplay() (Line: 387)
Twig\Template->yield() (Line: 44)
__TwigTemplate_954931822877dc81be93f06e93d55692->doDisplay() (Line: 387)
Twig\Template->yield() (Line: 343)
Twig\Template->display() (Line: 358)
Twig\Template->render() (Line: 35)
Twig\TemplateWrapper->render() (Line: 234)
Drupal\Core\Template\TwigEnvironment->renderInline() (Line: 54)
Drupal\Core\Render\Element\InlineTemplate::preRenderInlineTemplate()
call_user_func_array() (Line: 113)
Drupal\Core\Render\Renderer->doTrustedCallback() (Line: 870)
Drupal\Core\Render\Renderer->doCallback() (Line: 432)
Drupal\Core\Render\Renderer->doRender() (Line: 504)
Drupal\Core\Render\Renderer->doRender() (Line: 248)
Drupal\Core\Render\Renderer->render() (Line: 484)
Drupal\Core\Template\TwigExtension->escapeFilter() (Line: 44)
__TwigTemplate_cde85cbeced03ad7304f0b171ffab65b->doDisplay() (Line: 387)
Twig\Template->yield() (Line: 343)
Twig\Template->display() (Line: 358)
Twig\Template->render() (Line: 35)
Twig\TemplateWrapper->render() (Line: 33)
twig_render_template() (Line: 348)
Drupal\Core\Theme\ThemeManager->render() (Line: 491)
Drupal\Core\Render\Renderer->doRender() (Line: 248)
Drupal\Core\Render\Renderer->render() (Line: 484)
Drupal\Core\Template\TwigExtension->escapeFilter() (Line: 152)
__TwigTemplate_ef1cca93ddabfd78517b1af3bd9a2b55->block_content() (Line: 431)
Twig\Template->yieldBlock() (Line: 89)
__TwigTemplate_ef1cca93ddabfd78517b1af3bd9a2b55->block_wrapper() (Line: 431)
Twig\Template->yieldBlock() (Line: 53)
__TwigTemplate_ef1cca93ddabfd78517b1af3bd9a2b55->doDisplay() (Line: 387)
Twig\Template->yield() (Line: 343)
Twig\Template->display() (Line: 358)
Twig\Template->render() (Line: 35)
Twig\TemplateWrapper->render() (Line: 33)
twig_render_template() (Line: 348)
Drupal\Core\Theme\ThemeManager->render() (Line: 491)
Drupal\Core\Render\Renderer->doRender() (Line: 504)
Drupal\Core\Render\Renderer->doRender() (Line: 248)
Drupal\Core\Render\Renderer->render() (Line: 484)
Drupal\Core\Template\TwigExtension->escapeFilter() (Line: 178)
__TwigTemplate_d1ef5f3fac6f7f4a2af1062d6553c292->doDisplay() (Line: 387)
Twig\Template->yield() (Line: 343)
Twig\Template->display() (Line: 358)
Twig\Template->render() (Line: 35)
Twig\TemplateWrapper->render() (Line: 33)
twig_render_template() (Line: 348)
Drupal\Core\Theme\ThemeManager->render() (Line: 491)
Drupal\Core\Render\Renderer->doRender() (Line: 248)
Drupal\Core\Render\Renderer->render() (Line: 484)
Drupal\Core\Template\TwigExtension->escapeFilter() (Line: 128)
__TwigTemplate_601f39d425a21b830fcca07f8589f81f->doDisplay() (Line: 387)
Twig\Template->yield() (Line: 343)
Twig\Template->display() (Line: 358)
Twig\Template->render() (Line: 35)
Twig\TemplateWrapper->render() (Line: 33)
twig_render_template() (Line: 348)
Drupal\Core\Theme\ThemeManager->render() (Line: 491)
Drupal\Core\Render\Renderer->doRender() (Line: 248)
Drupal\Core\Render\Renderer->render() (Line: 158)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 638)
Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 153)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse() (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray()
call_user_func() (Line: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch() (Line: 186)
Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 53)
Drupal\Core\StackMiddleware\Session->handle() (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 28)
Drupal\Core\StackMiddleware\ContentLength->handle() (Line: 32)
Drupal\big_pipe\StackMiddleware\ContentLength->handle() (Line: 116)
Drupal\page_cache\StackMiddleware\PageCache->pass() (Line: 90)
Drupal\page_cache\StackMiddleware\PageCache->handle() (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 36)
Drupal\Core\StackMiddleware\AjaxPageState->handle() (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle() (Line: 741)
Drupal\Core\DrupalKernel->handle() (Line: 19)
Dale is using paragraphs (so entity reference revisions) and display suite (without ui_patterns_ds, so without the specific "DS Field" plugins).
More info in this Slack thread: https://drupal.slack.com/archives/C03MFN4D40J/p1736788312484209 (which is also dealing with #3499625: [2.0.0-rc2] Missing source for field prop entity to get access to the entity referenced by field items in the context of component per item field formatter
Proposed resolution
- Try to reproduce the error.
- Fix it.
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | Screenshot 2025-01-19 at 9.06.16 AM.png | 98.92 KB | dalemoore |
| #5 | Screenshot 2025-01-19 at 9.05.03 AM.png | 169.13 KB | dalemoore |
| #5 | Screenshot 2025-01-19 at 8.56.40 AM.png | 106.12 KB | dalemoore |
Issue fork ui_patterns-3500244
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
dalemoore commentedHere are my steps to reproduce. Some in the first steps sub-bullets may not be needed but including?
Sending a video of the steps in Slack.
Comment #3
just_like_good_vibesThanks for reporting.
After investigation, this error occurs when using the contrib module ds, when a layout from ui patterns is configured in a content entity display (here a paragraph), and in the layout settings, a source with the current entity is used.
it works in form configuration, but fails to properly render.
Indeed, for the moment, ui_patterns module is not providing itself a way to guess the current entity inside ds_entity_view layout options.
Comment #4
pdureau commentedUI Patterns target both Core & contrib modules, but we target by default only Core plugin types: Blocks, Layouts, Formatters...
Display Suite is using both:
ui_patterns_layoutssub-module if the usage of Dsipaly Suite is a "normal" (no weird additions or alteration)ui_patterns_dsis neededSo, are we 100% sure it is not working because of DS?
So, anyway, it seems there is something to do for the RC2.
Comment #5
dalemoore commentedTo my knowledge I'm not using a DS Field, but I could be wrong. Would I have to select one of these options in the layout dropdown under Manage Display to do something like that?
Or, this option would need to be enabled maybe:
Or something on this screen?
I'm not sure what exactly a DS Field is, I haven't used the things found in the last two screenshots before. In the past I would only use what's in the first screenshot, which allows me to override the template, add attributes/classes to fields, etc.
The only thing I'm using DS in this case is to select an SDC on the Manage Display screen layout dropdown without having to rely on Layout Builder (because I don't wish to manipulate layout visually, just do mapping to the SDC) or Field Layout (this module is to be deprecated and will be removed from Core, see this issue, this issue, and this issue). I haven't tried using Field Layout before, but I just did on a separate bare Drupal install. It doesn't seem to offer the ability to control field layout under "Manage display" any more, only under "Manage form display", so using Field Layout instead of Display Suite won't work.
Comment #7
just_like_good_vibesComment #8
just_like_good_vibesFor the moment, let's catch context exceptions and send a message to drupal logs...
Comment #9
pdureau commentedThe change is great, thanks.
Before merging and closing the issue, we need to create the related issue in https://www.drupal.org/project/issues/ui_patterns_ds
Do you want to do it?
Comment #10
pdureau commentedissue created #3501396: ContextException with entity
Duael is currently testing with Field Layout
Comment #11
duaelfrI have a similar issue with the following steps to reproduce (also reproduced by @g4mbini on a clean install):
I applied the patch from the MR and I'm still able to reproduce.
Here is my stack trace:
Comment #12
pdureau commentedComment #13
just_like_good_vibesexpect an answer and new version very soon, within minutes :)
Comment #14
just_like_good_vibesComment #15
just_like_good_vibeswould you test please ?
Comment #16
just_like_good_vibesi just added some more fixes..
Comment #17
dalemoore commentedI tried the updated code as a patch (alongside the other issue's code which I still have patched in), switching my 'Social Links' component to use 'Rendered entity' instead of 'Components per item', then in the paragraph type mapping the fields to the props. Instead of the ContextException I now get this:
Oh, and upon first integrating the patch and running
composer update, I get this error until I dodrush crto clear caches:Comment #18
just_like_good_vibesmore goodness pushed :)
Comment #19
pdureau commentedIt works well. The data is retrieved and send to the prop.
Sounds great, no? However all this was done without switching to the MR branch! Maybe one of the many fix we did today was also fixing this issue.
Comment #20
pdureau commentedSo, what do we do? We merge or we cancel this MR?
Comment #21
pdureau commentedOr maybe it is a DS specific issue? I have tested only with Field Layout
Comment #22
just_like_good_vibesFor Display suite users, one can look at the solution shown in that issue. It will be implemented in the future in
ui_patterns_dsmodule.Comment #23
just_like_good_vibesComment #26
just_like_good_vibesComment #27
duaelfrI woke up this morning to see this fixed.
Congratulations and many thanks for this!!