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)

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

gargsuchi created an issue. See original summary.

gargsuchi’s picture

gargsuchi’s picture

Status: Active » Needs review
gg24’s picture

Hi @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!

Status: Needs review » Needs work

The last submitted patch, 4: easy_breadcrumb-fix-warning-2925736-4.patch, failed testing. View results

gg24’s picture

Status: Needs work » Needs review
FileSize
992 bytes
gg24’s picture

Assigned: gargsuchi » Unassigned
guptahemant’s picture

Status: Needs review » Reviewed & tested by the community

hi @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,

gargsuchi’s picture

Minor nitpick - fixed a typo in the comment and also shortened the comment.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 9: easy_breadcrumb-fix-warning-2925736-9.patch, failed testing. View results

gargsuchi’s picture

Greg Boggs’s picture

Looks good! Thanks Gargsuchi!

gargsuchi’s picture

Status: Needs work » Reviewed & tested by the community
bmcclure’s picture

I'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.

Greg Boggs’s picture

Wanna do a screen share?

Greg Boggs’s picture

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

bmcclure’s picture

Actually, 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!

martin.davidson’s picture

I'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:

$title = [
  #markup = "Main navigation",
  #allowed_tags = [
    0 = "a",
    1 = "em",
    ...
  ]
]

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.

martin.davidson’s picture

Status: Reviewed & tested by the community » Needs work
bmcclure’s picture

Here'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.

loopduplicate’s picture

FileSize
912 bytes

Here's an interdiff between #11 and #20.

Greg Boggs’s picture

@loop,

What do you think, can you commit and push what you believe is the correct solution? :)

loopduplicate’s picture

Assigned: Unassigned » loopduplicate

@greg working on it

loopduplicate’s picture

Here'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.

Greg Boggs’s picture

That looks correct.

loopduplicate’s picture

Assigned: Unassigned » loopduplicate
Status: Needs review » Reviewed & tested by the community

OK, marking as RTBC and will get this committed to the dev branch. Let's credit all contributors to this issue. Thanks :)

  • loopduplicate committed fcaf54a on 8.x-1.x
    Issue #2925736 by gargsuchi, gg24, loopduplicate, bmcclure, Greg Boggs,...
loopduplicate’s picture

Assigned: loopduplicate » Unassigned
Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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

Christopher Riley’s picture

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

tim-diels’s picture

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