[2.0.0-rc2] ContextException with entity:paragraph

Created on 16 January 2025, 6 days ago

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 πŸ“Œ Introduce a new source to get access to the current "i-th" referenced entity from a field entity reference in the context of component per item field formatter Active

Proposed resolution

  1. Try to reproduce the error.
  2. Fix it.
πŸ“Œ Task
Status

Active

Version

2.0

Component

Code

Created by

πŸ‡«πŸ‡·France pdureau Paris

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

Merge Requests

Comments & Activities

  • Issue created by @pdureau
  • πŸ‡ΊπŸ‡ΈUnited States dalemoore

    Here are my steps to reproduce. Some in the first steps sub-bullets may not be needed but including?

    1. You will need some SDCs to use. I have a parent SDC called Social Links and a child one called Social Link. (@pdureau should already have these, they were included in the Slack conversation)
    2. Make sure you have Display Suite and Display Suite Extras installed. This is used to select a component layout within Manage Display. Under Display Suite (admin/structure/ds/settings), I have these settings:
      • Enable field templates
      • Enable field templates in Layout Builder
      • Default Field Template: Expert
      • Under Extra fields, nothing selected
      • Under Other, "Use field names in templates" and "Exclude Display Suite Layouts in Layout Builder" are checked"
      • Nothing checked in BC settings
    3. Create a paragraph type (in my case, it's called Social Link - this is the child component) and add whatever fields you want to it, including at least one Entity Reference field (I have a taxonomy term one called Network that references social network names, e.g., Facebook, Instagram, etc.).
    4. Create a block type (in my case, it's called Social Links - this is the parent component) and add whatever fields you want, including one Entity Reference Revisions/Paragraphs field that uses the previously-created paragraph type.
    5. Go ahead and add an instance of the block somewhere on your page in a region (I'm not using Layout Builder here, just the block UI).
    6. Under Manage Display for the block type, make sure it's set to "Referenced entity" under Format for the Entity Reference Revisions field. That's all you need here.
    7. Under Manage Display for the paragraph type, with Display Suite installed, under "Current layout" select the SDC you want to use from the dropdown list (for me, it is the child component Social Link) and save.
    8. Go to "Layout settings" still in the paragraph type, and map the props to the appropriate fields. The only options to start are "Data from a field" or "Referenced entities", there is no initial "Prop: entity" available like there is when using "Components per item" in the sibling issue. πŸ“Œ Introduce a new source to get access to the current "i-th" referenced entity from a field entity reference in the context of component per item field formatter Active I choose "Data from a field" for each.
    9. Once all fields are mapped, save, then go back and refresh the page to view your block.
    10. I get a ContextException error message.

    Sending a video of the steps in Slack.

  • πŸ‡«πŸ‡·France just_like_good_vibes PARIS

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

  • πŸ‡«πŸ‡·France pdureau Paris

    Indeed, for the moment, ui_patterns module is not providing itself a way to guess the current entity inside ds_entity_view layout options

    UI Patterns target both Core & contrib modules, but we target by default only Core plugin types: Blocks, Layouts, Formatters...

    Display Suite is using both:

    • core plugin types (Layout for example) and it is supposed to work directly with ui_patterns_layouts sub-module if the usage of Dsipaly Suite is a "normal" (no weird additions or alteration)
    • a custom plugin type ("DS Field"), for this one, ui_patterns_ds is needed

    So, are we 100% sure it is not working because of DS?

    So, anyway, it seems there is something to do for the RC2.

  • πŸ‡ΊπŸ‡ΈUnited States dalemoore

    a custom plugin type ("DS Field"), for this one, ui_patterns_ds is needed

    To 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 πŸ“Œ Inform users that Field Layout is deprecated Active , this issue πŸ“Œ [META] Enable layout builder for form displays, and deprecate field_layout Postponed , and this issue πŸ“Œ Move Field Layout data model and API directly into \Drupal\Core\Entity\EntityDisplayBase Needs work ). 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.

  • πŸ‡«πŸ‡·France just_like_good_vibes PARIS

    For the moment, let's catch context exceptions and send a message to drupal logs...

  • Pipeline finished with Success
    1 day ago
    Total: 594s
    #401046
  • πŸ‡«πŸ‡·France pdureau Paris

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

Production build 0.71.5 2024