Widget error on node preview
>>> [!note] Migrated issue <!-- Drupal.org comment --> <!-- Migrated from issue #3463209. --> Reported by: [rclemings](https://www.drupal.org/user/917304) Related to !17 >>> <h3 id="summary-problem-motivation">Problem/Motivation</h3> <p>I'm seeing the following fatal (WSOD) error, or similar (e.g. "danse_content.api.subscribe" instead of "danse_content.api.unsubscribe") when using the "preview" button on a node/add page for a content type that has a DANSE widget in its display.</p> <p>If my diagnosis is correct, it's failing because the node doesn't exist yet and the call to $entity-&gt;id() in modules/content/src/Service.php yields nothing.</p> <pre>The website encountered an unexpected error. Try again later.<br><br>Symfony\Component\Routing\Exception\InvalidParameterException: Parameter "entity_id" for route "danse_content.api.unsubscribe" must match "[^/]++" ("" given) to generate a corresponding URL. in Drupal\Core\Routing\UrlGenerator-&gt;doGenerate() (line 209 of core/lib/Drupal/Core/Routing/UrlGenerator.php).<br>Drupal\Core\Routing\UrlGenerator-&gt;getInternalPathFromRoute('danse_content.api.unsubscribe', Object, Array, Array) (Line: 300)<br>Drupal\Core\Routing\UrlGenerator-&gt;generateFromRoute('danse_content.api.unsubscribe', Array, Array, 1) (Line: 108)<br>Drupal\Core\Render\MetadataBubblingUrlGenerator-&gt;generateFromRoute('danse_content.api.unsubscribe', Array, Array, 1) (Line: 765)<br>Drupal\Core\Url-&gt;toString(1) (Line: 183)<br>Drupal\Core\Utility\LinkGenerator-&gt;generate('Unsubscribe from all Job advertisement content when it gets published', Object) (Line: 102)<br>Drupal\Core\Render\Element\Link::preRenderLink(Array)<br>call_user_func_array(Array, Array) (Line: 113)<br>Drupal\Core\Render\Renderer-&gt;doTrustedCallback(Array, Array, 'Render #pre_render callbacks must be methods of a class that implements \Drupal\Core\Security\TrustedCallbackInterface or be an anonymous function. The callback was %s. See https://www.drupal.org/node/2966725', 'exception', 'Drupal\Core\Render\Element\RenderCallbackInterface') (Line: 870)<br>Drupal\Core\Render\Renderer-&gt;doCallback('#pre_render', Array, Array) (Line: 432)<br>Drupal\Core\Render\Renderer-&gt;doRender(Array, ) (Line: 248)<br>Drupal\Core\Render\Renderer-&gt;render(Array) (Line: 475)<br>Drupal\Core\Template\TwigExtension-&gt;escapeFilter(Object, Array, 'html', NULL, 1) (Line: 60)<br>__TwigTemplate_1051a67965ebcd18a38f9a19ee0bc9d5-&gt;doDisplay(Array, Array) (Line: 360)<br>Twig\Template-&gt;yield(Array) (Line: 335)<br>Twig\Template-&gt;render(Array) (Line: 38)<br>Twig\TemplateWrapper-&gt;render(Array) (Line: 33)<br>twig_render_template('themes/contrib/bootstrap/templates/bootstrap/item-list--dropdown.html.twig', Array) (Line: 348)<br>Drupal\Core\Theme\ThemeManager-&gt;render('item_list__dropdown', Array) (Line: 491)<br>Drupal\Core\Render\Renderer-&gt;doRender(Array, ) (Line: 248)<br>Drupal\Core\Render\Renderer-&gt;render(Array) (Line: 475)<br>Drupal\Core\Template\TwigExtension-&gt;escapeFilter(Object, Array, 'html', NULL, 1) (Line: 52)<br>__TwigTemplate_061bfea4e5d7a0a1c3c9fb12f411623b-&gt;doDisplay(Array, Array) (Line: 360)<br>Twig\Template-&gt;yield(Array) (Line: 335)<br>Twig\Template-&gt;render(Array) (Line: 38)<br>Twig\TemplateWrapper-&gt;render(Array) (Line: 33)<br>twig_render_template('themes/contrib/bootstrap/templates/bootstrap/bootstrap-dropdown.html.twig', Array) (Line: 348)<br>Drupal\Core\Theme\ThemeManager-&gt;render('links', Array) (Line: 491)<br>Drupal\Core\Render\Renderer-&gt;doRender(Array) (Line: 504)<br>Drupal\Core\Render\Renderer-&gt;doRender(Array, ) (Line: 248)<br>Drupal\Core\Render\Renderer-&gt;render(Array) (Line: 475)<br>Drupal\Core\Template\TwigExtension-&gt;escapeFilter(Object, Array, 'html', NULL, 1) (Line: 231)<br>__TwigTemplate_abd3d0aa47e2204b1749db1440448d06-&gt;doDisplay(Array, Array) (Line: 360)<br>Twig\Template-&gt;yield(Array) (Line: 335)<br>Twig\Template-&gt;render(Array) (Line: 38)<br>Twig\TemplateWrapper-&gt;render(Array) (Line: 33)<br>twig_render_template('themes/custom/nasw/templates/node/node.html.twig', Array) (Line: 348)<br>Drupal\Core\Theme\ThemeManager-&gt;render('node', Array) (Line: 491)<br>Drupal\Core\Render\Renderer-&gt;doRender(Array, ) (Line: 248)<br>Drupal\Core\Render\Renderer-&gt;render(Array, ) (Line: 238)<br>Drupal\Core\Render\MainContent\HtmlRenderer-&gt;Drupal\Core\Render\MainContent\{closure}() (Line: 638)<br>Drupal\Core\Render\Renderer-&gt;executeInRenderContext(Object, Object) (Line: 239)<br>Drupal\Core\Render\MainContent\HtmlRenderer-&gt;prepare(Array, Object, Object) (Line: 128)<br>Drupal\Core\Render\MainContent\HtmlRenderer-&gt;renderResponse(Array, Object, Object) (Line: 90)<br>Drupal\Core\EventSubscriber\MainContentViewSubscriber-&gt;onViewRenderArray(Object, 'kernel.view', Object)<br>call_user_func(Array, Object, 'kernel.view', Object) (Line: 111)<br>Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher-&gt;dispatch(Object, 'kernel.view') (Line: 186)<br>Symfony\Component\HttpKernel\HttpKernel-&gt;handleRaw(Object, 1) (Line: 76)<br>Symfony\Component\HttpKernel\HttpKernel-&gt;handle(Object, 1, 1) (Line: 53)<br>Drupal\Core\StackMiddleware\Session-&gt;handle(Object, 1, 1) (Line: 48)<br>Drupal\Core\StackMiddleware\KernelPreHandle-&gt;handle(Object, 1, 1) (Line: 28)<br>Drupal\Core\StackMiddleware\ContentLength-&gt;handle(Object, 1, 1) (Line: 32)<br>Drupal\big_pipe\StackMiddleware\ContentLength-&gt;handle(Object, 1, 1) (Line: 106)<br>Drupal\page_cache\StackMiddleware\PageCache-&gt;pass(Object, 1, 1) (Line: 85)<br>Drupal\page_cache\StackMiddleware\PageCache-&gt;handle(Object, 1, 1) (Line: 48)<br>Drupal\Core\StackMiddleware\ReverseProxyMiddleware-&gt;handle(Object, 1, 1) (Line: 51)<br>Drupal\Core\StackMiddleware\NegotiationMiddleware-&gt;handle(Object, 1, 1) (Line: 36)<br>Drupal\Core\StackMiddleware\AjaxPageState-&gt;handle(Object, 1, 1) (Line: 51)<br>Drupal\Core\StackMiddleware\StackedHttpKernel-&gt;handle(Object, 1, 1) (Line: 741)<br>Drupal\Core\DrupalKernel-&gt;handle(Object) (Line: 19)</pre><h4 id="summary-steps-reproduce">Steps to reproduce</h4> <p>Set "Allow individual entity subscription" and/or "Allow entity type subscription" to true for a combination of role and content type (/admin/structure/types/manage/CONTENTTYPE, then DANSE tab). (It probably affects "Allow related entity subscription" too; I haven't tried it.) Then create a node as a user with that role, and use the preview button to preview the node before saving.</p> <h3 id="summary-proposed-resolution">Proposed resolution</h3> <p>Check for $entity-&gt;id() before building the widget.</p> <h3 id="summary-remaining-tasks">Remaining tasks</h3> <p>Merge request coming momentarily.</p> <h3 id="summary-ui-changes">User interface changes</h3> <p>None</p> <h3 id="summary-api-changes">API changes</h3> <p>None</p> <h3 id="summary-data-model-changes">Data model changes</h3> <p>None</p>
issue