Problem/Motivation

When discarding changes in layout builder on an entity type, an error occurs and I think it's due to a missing check, see details below:

Location:	https://example.com/de/admin/structure/types/manage/page/display/default/layout/discard-changes
Referrer:	https://example.com/de/admin/structure/types/manage/page/display/default/layout
Message:	TypeError: Drupal\easy_breadcrumb\EasyBreadcrumbBuilder::truncator(): Argument #1 ($title) must be of type string, null given, called in /web/modules/contrib/easy_breadcrumb/src/EasyBreadcrumbBuilder.php on line 514 in Drupal\easy_breadcrumb\EasyBreadcrumbBuilder->truncator() (Zeile 960 in /web/modules/contrib/easy_breadcrumb/src/EasyBreadcrumbBuilder.php)
#0 /web/modules/contrib/easy_breadcrumb/src/EasyBreadcrumbBuilder.php(514): Drupal\easy_breadcrumb\EasyBreadcrumbBuilder->truncator()
#1 /web/core/lib/Drupal/Core/Breadcrumb/BreadcrumbManager.php(83): Drupal\easy_breadcrumb\EasyBreadcrumbBuilder->build()
#2 /web/core/modules/system/src/Plugin/Block/SystemBreadcrumbBlock.php(72): Drupal\Core\Breadcrumb\BreadcrumbManager->build()
#3 /web/core/modules/block/src/BlockViewBuilder.php(171): Drupal\system\Plugin\Block\SystemBreadcrumbBlock->build()
#4 [internal function]: Drupal\block\BlockViewBuilder::preRender()
#5 /web/core/lib/Drupal/Core/Security/DoTrustedCallbackTrait.php(101): call_user_func_array()
#6 /web/core/lib/Drupal/Core/Render/Renderer.php(781): Drupal\Core\Render\Renderer->doTrustedCallback()
#7 /web/core/lib/Drupal/Core/Render/Renderer.php(372): Drupal\Core\Render\Renderer->doCallback()
#8 /web/core/lib/Drupal/Core/Render/Renderer.php(444): Drupal\Core\Render\Renderer->doRender()
#9 /web/core/lib/Drupal/Core/Render/Renderer.php(200): Drupal\Core\Render\Renderer->doRender()
#10 /web/core/lib/Drupal/Core/Template/TwigExtension.php(450): Drupal\Core\Render\Renderer->render()
#11 /web/sites/default/files/php/twig/60a3d8ec8b386_page.html.twig_OQLu4yNZH1CagHozBhf_BMSrM/anbpbDqPX6jvkbm7kVReXsF4u9cY0Wg-nwCS2r8vrNE.php(136): Drupal\Core\Template\TwigExtension->escapeFilter()
#12 /vendor/twig/twig/src/Template.php(405): __TwigTemplate_933796aa29b2ed0c9b640131da125c4bb4073eef73d9c6a09f700545da14bfee->doDisplay()
#13 /vendor/twig/twig/src/Template.php(378): Twig\Template->displayWithErrorHandling()
#14 /vendor/twig/twig/src/Template.php(390): Twig\Template->display()
#15 /web/core/themes/engines/twig/twig.engine(65): Twig\Template->render()
#16 /web/core/lib/Drupal/Core/Theme/ThemeManager.php(384): twig_render_template()
#17 /web/core/lib/Drupal/Core/Render/Renderer.php(431): Drupal\Core\Theme\ThemeManager->render()
#18 /web/core/lib/Drupal/Core/Render/Renderer.php(200): Drupal\Core\Render\Renderer->doRender()
#19 /web/core/lib/Drupal/Core/Template/TwigExtension.php(450): Drupal\Core\Render\Renderer->render()
#20 /web/sites/default/files/php/twig/60a3d8ec8b386_html.html.twig_lR5SZYCpERTbdPWnnAZQjDwTA/MOXcEw6Cmq1bIygwnm6GLFNXdiifZDFSF_XkCDMKB2M.php(93): Drupal\Core\Template\TwigExtension->escapeFilter()
#21 /vendor/twig/twig/src/Template.php(405): __TwigTemplate_6b69f4862c2052aaedd91075b031f47a3380c64ce11011c16972e04cfe06d9a9->doDisplay()
#22 /vendor/twig/twig/src/Template.php(378): Twig\Template->displayWithErrorHandling()
#23 /vendor/twig/twig/src/Template.php(390): Twig\Template->display()
#24 /web/core/themes/engines/twig/twig.engine(65): Twig\Template->render()
#25 /web/core/lib/Drupal/Core/Theme/ThemeManager.php(384): twig_render_template()
#26 /web/core/lib/Drupal/Core/Render/Renderer.php(431): Drupal\Core\Theme\ThemeManager->render()
#27 /web/core/lib/Drupal/Core/Render/Renderer.php(200): Drupal\Core\Render\Renderer->doRender()
#28 /web/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(162): Drupal\Core\Render\Renderer->render()
#29 /web/core/lib/Drupal/Core/Render/Renderer.php(573): Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}()
#30 /web/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(163): Drupal\Core\Render\Renderer->executeInRenderContext()
#31 /web/core/lib/Drupal/Core/EventSubscriber/MainContentViewSubscriber.php(90): Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse()
#32 [internal function]: Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray()
#33 /web/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php(142): call_user_func()
#34 /vendor/symfony/http-kernel/HttpKernel.php(163): Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch()
#35 /vendor/symfony/http-kernel/HttpKernel.php(80): Symfony\Component\HttpKernel\HttpKernel->handleRaw()
#36 /web/core/lib/Drupal/Core/StackMiddleware/Session.php(57): Symfony\Component\HttpKernel\HttpKernel->handle()
#37 /web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(47): Drupal\Core\StackMiddleware\Session->handle()
#38 /web/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\Core\StackMiddleware\KernelPreHandle->handle()
#39 /web/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass()
#40 /web/core/modules/ban/src/BanMiddleware.php(50): Drupal\page_cache\StackMiddleware\PageCache->handle()
#41 /web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(47): Drupal\ban\BanMiddleware->handle()
#42 /web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(52): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle()
#43 /vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle()
#44 /web/core/lib/Drupal/Core/DrupalKernel.php(706): Stack\StackedHttpKernel->handle()
#45 /web/index.php(19): Drupal\Core\DrupalKernel->handle()
#46 {main}
.

Steps to reproduce

Open layout builder in a node type display
Click "Discard Changes"
=> Error

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Command icon 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

Anybody created an issue. See original summary.

greg boggs’s picture

It looks like layout builder fails to set a title on the discard form.

anybody’s picture

Thank you @Greg,

yes I think so too. But I also think it would make sense to catch that case in easy_breadcrumb?

So I'd suggest to add a check for that and create an issue for Layout Builder, if there are no good reasons to add a title?

anybody’s picture

Status: Active » Needs review
anybody’s picture

Just tested, works! And indeed Layout Builder misses setting a title!

Anywas easy_breadcrumb should not fail in that case.

anybody’s picture

Created the issue in Drupal core layout builder: #3214744: Layout builder discard confirm form misses to set a page title

renatog’s picture

Status: Needs review » Needs work

I've just added a comment on PR

What do you think about adds !empty() on your conditional?

I like to use !empty especially to avoid unexpected errors

So for example:

Stead of:

if ($title && $this->config->get(EasyBreadcrumbConstants::TRUNCATOR_MODE)) {

To:

if (!empty($title) && $this->config->get(EasyBreadcrumbConstants::TRUNCATOR_MODE)) {

Just a suggestion

anybody’s picture

Hi @RenatoG,

I'm a big fan of !empty() and I sticked to the implementation above where there's also no !empty() used for $title. So I'd suggest to then change both? A title of "0" doesn't make much sense to me anyway.

renatog’s picture

So I'd suggest to then change both?

Yes, I fully agree. As we will change one we can update both. Go ahead

It's a good practice and It'll no impact nothing

neslee canil pinto’s picture

Hey, I think we should not fix this in EB, as it's causing by Drupal core's layout builder module, better we create a patch for Drupal core's layout builder module, just a thought. What do you guys think 🤔 ?
As told by Greg setting the title for the particular page will solve this and this is a bug in the core, and thanks to anybody for creating the issue, will follow up there.

anybody’s picture

Status: Needs work » Needs review

Re @Neslee Canil Pinto:

Hey, I think we should not fix this in EB, as it's causing by Drupal core's layout builder module, better we create a patch for Drupal core's layout builder module, just a thought. What do you guys think 🤔 ?
As told by Greg setting the title for the particular page will solve this and this is a bug in the core, and thanks to anybody for creating the issue, will follow up there.

No I think easy_breadcrumb should not presume a title exists and fail with an error here, so we should fix it in both.

Re @RenatoG: Done! :) Please review.

renatog’s picture

Status: Needs review » Reviewed & tested by the community

No I think easy_breadcrumb should not presume a title exists and fail with an error here, so we should fix it in both.

+1, I agree with @anybody on #12

Looks good for me

neslee canil pinto’s picture

@Anybody ok, seems reasonable instead of a just $title -> !empty($title) will not break the existing functionality. Had a talk earlier about this with @Greg Boggs via slack, and we thought we will patch core and go forward about this, but as this is solving in EB which will not block you/others and solves title call back from core too. I will go ahead and commit this.

neslee canil pinto’s picture

Status: Reviewed & tested by the community » Fixed
anybody’s picture

@Neslee Canil Pinto thank you very much! :)

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.