Problem/Motivation

The following error is produced when clicking the Moderation sidebar link in the toolbar. This is because the routeMatch finds the moderation sidebar route which doesn't have an entity type's ID route parameter (e.g node), instead it uses entity_type and entity.

Warning: array_flip(): Can only flip string and integer values, entry skipped in Drupal\Core\Entity\EntityStorageBase->loadMultiple() (line 312 of /data/app/core/lib/Drupal/Core/Entity/EntityStorageBase.php) #0 /data/app/core/includes/bootstrap.inc(347): _drupal_error_handler_real() #1 [internal function]: _drupal_error_handler() #2 /data/app/core/lib/Drupal/Core/Entity/EntityStorageBase.php(312): array_flip() #3 /data/app/core/lib/Drupal/Core/Entity/EntityStorageBase.php(296): Drupal\Core\Entity\EntityStorageBase->loadMultiple() #4 /data/app/modules/contrib/entity_hierarchy/src/Routing/ReorderChildrenAccess.php(85): Drupal\Core\Entity\EntityStorageBase->load() #5 [internal function]: Drupal\entity_hierarchy\Routing\ReorderChildrenAccess->access()

Steps to reproduce

Install Moderation sidebar
Click Sidebar link in the Toolbar

Proposed resolution

Either
- Check for $entity being NULL
- OR fallback to a generic entity route parameter key.

CommentFileSizeAuthor
#2 fix-null-entity-3300352.patch690 bytestinny

Comments

acbramley created an issue. See original summary.

tinny’s picture

Status: Active » Needs review
StatusFileSize
new690 bytes

I created a patch which checks for empty entity.

danflanagan8’s picture

Status: Needs review » Reviewed & tested by the community

I ran into this exact same problem with a site using moderation_sidebar and entity_hierarchy. Somehow node is null in some cases. I don't understand why, but sometimes this results in an ajax 404 instead of the gentler array_flip warning. This patch definitely fixes the error and life is good.

Thanks!

larowlan’s picture

Status: Reviewed & tested by the community » Needs review

Any way we can write a test for this?

acbramley’s picture

I think you could set up a test module with a route similar to this

moderation_sidebar.sidebar:
  path: '/moderation-sidebar/{entity_type}/{entity}'
  defaults:
    _controller: '\Drupal\moderation_sidebar\Controller\ModerationSidebarController::sideBar'
    _title_callback: '\Drupal\moderation_sidebar\Controller\ModerationSidebarController::title'
  requirements:
    _permission: 'use moderation sidebar'
    _entity_access: 'entity.moderation-sidebar'
  options:
    parameters:
      entity:
        type: entity:{entity_type}

  • larowlan committed 4e913d6 on 3.x
    Issue #3300352 by tinny: array_flip warning when used with...
larowlan’s picture

Status: Needs review » Fixed

Doesn't seem worth the effort for a two line change that only impacts people with this module.

Committed and rolling a 3.3.2 release

Status: Fixed » Closed (fixed)

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