Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Since I installed this module, I have been getting this error in my logs:
Warning: array_key_exists(): The first argument should be either a string or an integer in Drupal\easy_breadcrumb\EasyBreadcrumbBuilder->build() (line 207 of /<path to docroot>/modules/contrib/easy_breadcrumb/src/EasyBreadcrumbBuilder.php) #0 /path to docroot/core/includes/bootstrap.inc(566): _drupal_error_handler_real(2, 'array_key_exist...', '/var/beetbox/do...', 207, Array)
Comment | File | Size | Author |
---|---|---|---|
#24 | interdiff-2925736-20-24.txt | 2.67 KB | loopduplicate |
#24 | easy_breadcrumb-fix-warning-2925736-24.patch | 2.32 KB | loopduplicate |
| |||
#21 | interdiff-2925736-11-20.txt | 912 bytes | loopduplicate |
#20 | easy_breadcrumb-title-object-or-array-2925736-20.patch | 1.09 KB | bmcclure |
| |||
#2 | easy_breadcrumb-fix-warning-2925736-1.patch | 857 bytes | gargsuchi |
|
Comments
Comment #2
gargsuchi CreditAttribution: gargsuchi at Salsa Digital for Department of Premier and Cabinet - Victoria, Australia commentedComment #3
gargsuchi CreditAttribution: gargsuchi at Salsa Digital for Department of Premier and Cabinet - Victoria, Australia commentedComment #4
gg24 CreditAttribution: gg24 as a volunteer and at QED42 commentedHi @gargsuchi,
I have tested the above patch. It applies cleanly but If the current route is an admin route than $title returns an object but if the $title is a string which is the case of non-admin route than directly applying getUntranslatedString() throws an error. In that case I am checking if it is an object than apply the method else fetch the $title using $this->titleResolver->getTitle().
Please review the patch.
Thanks!
Comment #6
gg24 CreditAttribution: gg24 as a volunteer and at QED42 commentedComment #7
gg24 CreditAttribution: gg24 as a volunteer and at QED42 commentedComment #8
guptahemant CreditAttribution: guptahemant as a volunteer and at QED42 commentedhi @gg24,
I have applied your patch in #6 ,it applies cleanly and resolves the mentioned issue,Hence marking the issue as RTBC.
Steps followed are:
1. Installed the module.
2. Gone to configuration form and saved the settings.(This didn't produce the issue)
3. Then I enabled "Use the real page title when available" option and the issue appears as mentioned.
4. Then I applied the patch and it resolves the warning.
5. Tested again by enabling and disabling "Use the real page title when available" this option
Thanks,
Comment #9
gargsuchi CreditAttribution: gargsuchi at Salsa Digital for Department of Premier and Cabinet - Victoria, Australia commentedMinor nitpick - fixed a typo in the comment and also shortened the comment.
Comment #11
gargsuchi CreditAttribution: gargsuchi at Salsa Digital for Department of Premier and Cabinet - Victoria, Australia commentedComment #12
Greg BoggsLooks good! Thanks Gargsuchi!
Comment #13
gargsuchi CreditAttribution: gargsuchi at Salsa Digital for Department of Premier and Cabinet - Victoria, Australia commentedComment #14
bmcclure CreditAttribution: bmcclure as a volunteer and at Top Floor commentedI'm still getting this same error on most admin pages when using the latest patch here. I no longer get it multiple times, but I still get it one time on each page the first time it's loaded. I verified the patch is applied and the code it introduces is present, but there must still be a way that $title is not a string when it gets through:
Warning: array_key_exists(): The first argument should be either a string or an integer in Drupal\easy_breadcrumb\EasyBreadcrumbBuilder->build() (line 219 of modules/easy_breadcrumb/src/EasyBreadcrumbBuilder.php).
I'm not sure what could cause this yet.
Comment #15
Greg BoggsWanna do a screen share?
Comment #16
Greg BoggsWhat we're going to want to do is to set a break point on line 219.
For that to work you need:
1. PHP installed locally with the site installed.
2. Xdebug installed
3. PHPStorm or any other free IDE like netbeans.
4. Xdebug configured in your IDE.
Then we set the break point, load the page and see what the value of the variable is.
Comment #17
bmcclure CreditAttribution: bmcclure as a volunteer and at Top Floor commentedActually, I believe I must have been experiencing some sort of Pantheon issue with the old version of the file still being in place somehow. I can't seem to reproduce the issue in my local development environment. If I can reproduce the issue again, I'll let you know what the value of
$title
is when the issue occurs. But in the meantime, it seems this should probably still be RTBC. Thanks!Comment #18
martin.davidson CreditAttribution: martin.davidson commentedI'm on a menu admin screen (/admin/structure/menu/manage/main) with the patch enabled, and I'm getting
Warning: array_key_exists(): The first argument should be either a string or an integer in Drupal\easy_breadcrumb\EasyBreadcrumbBuilder->build() (line 213 of modules/contrib/easy_breadcrumb/src/EasyBreadcrumbBuilder.php).
When I throw a breakpoint there, this is what the $title variable is:
Doesn't look like the patch is expecting an array. Is it as simple as checking if it's an array and seeing if there's a #markup key? I don't have enough context.
Comment #19
martin.davidson CreditAttribution: martin.davidson commentedComment #20
bmcclure CreditAttribution: bmcclure as a volunteer and at Top Floor commentedHere's another attempt.
First, is_object() is too generic I believe--so I'm using instanceof to make sure it's got the method that we actually need.
Second, as discovered it could be an array with a #markup key containing the string, so I've accounted for that.
Third, I've ensured it's a string before trying to use it with is_string in case one of the conditionals did not convert it to a proper title.
This is working for me in all cases I've tested so far.
Comment #21
loopduplicateHere's an interdiff between #11 and #20.
Comment #22
Greg Boggs@loop,
What do you think, can you commit and push what you believe is the correct solution? :)
Comment #23
loopduplicate@greg working on it
Comment #24
loopduplicateHere's an updated patch with a bit more commenting. It also includes a log message if another type of data is encountered.
I've included an interdiff between 20 and 24.
Comment #25
Greg BoggsThat looks correct.
Comment #26
loopduplicateOK, marking as RTBC and will get this committed to the dev branch. Let's credit all contributors to this issue. Thanks :)
Comment #28
loopduplicateComment #30
Christopher Riley CreditAttribution: Christopher Riley commentedI am getting the same error when I install Search API and try to edit the default content index. Here is the trace:
Warning: array_key_exists(): The first argument should be either a string or an integer in Drupal\easy_breadcrumb\EasyBreadcrumbBuilder->build() (line 229 of modules/contrib/easy_breadcrumb/src/EasyBreadcrumbBuilder.php).
Drupal\easy_breadcrumb\EasyBreadcrumbBuilder->build(Object) (Line: 83)
Drupal\Core\Breadcrumb\BreadcrumbManager->build(Object) (Line: 72)
Drupal\system\Plugin\Block\SystemBreadcrumbBlock->build() (Line: 203)
Drupal\block\BlockViewBuilder::preRender(Array)
call_user_func('Drupal\block\BlockViewBuilder::preRender', Array) (Line: 378)
Drupal\Core\Render\Renderer->doRender(Array) (Line: 450)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 195)
Drupal\Core\Render\Renderer->render(Array) (Line: 490)
Drupal\Core\Template\TwigExtension->escapeFilter(Object, Array, 'html', NULL, 1) (Line: 59)
__TwigTemplate_f8a17f041581af9829850fd45db45c2b69d8b3a60b80408d416da5d23dbccb61->doDisplay(Array, Array) (Line: 432)
Twig_Template->displayWithErrorHandling(Array, Array) (Line: 403)
Twig_Template->display(Array) (Line: 411)
Twig_Template->render(Array) (Line: 64)
twig_render_template('core/themes/seven/templates/page.html.twig', Array) (Line: 384)
Drupal\Core\Theme\ThemeManager->render('page', Array) (Line: 437)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 195)
Drupal\Core\Render\Renderer->render(Array) (Line: 490)
Drupal\Core\Template\TwigExtension->escapeFilter(Object, Array, 'html', NULL, 1) (Line: 90)
__TwigTemplate_be8c7bbb9c824f2826368d7c8da984c6279779db72a67fd8056a00bb23b816f2->doDisplay(Array, Array) (Line: 432)
Twig_Template->displayWithErrorHandling(Array, Array) (Line: 403)
Twig_Template->display(Array) (Line: 411)
Twig_Template->render(Array) (Line: 64)
twig_render_template('core/themes/classy/templates/layout/html.html.twig', Array) (Line: 384)
Drupal\Core\Theme\ThemeManager->render('html', Array) (Line: 437)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 195)
Drupal\Core\Render\Renderer->render(Array) (Line: 147)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 582)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 148)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object, Object) (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object, 'kernel.view', Object)
call_user_func(Array, Object, 'kernel.view', Object) (Line: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('kernel.view', Object) (Line: 156)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 68)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 99)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 78)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 50)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 657)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
Suggestions?
Comment #31
tim-dielsHi Christopher Riley,
Please take a look at https://www.drupal.org/project/easy_breadcrumb/issues/2960546
This is almost the same issue and the patch solves the problem.