With entity_hierarchy enabled but with other views in place (e.g. node/%media/media) calls to, say, node/18/media fail:

TypeError: Argument 1 passed to Drupal\entity_hierarchy\Information\ParentCandidate::getCandidateFields() must implement interface Drupal\Core\Entity\EntityInterface, string given, called in /var/www/html/drupal/web/modules/contrib/entity_hierarchy/src/Routing/ReorderChildrenAccess.php on line 69 in Drupal\entity_hierarchy\Information\ParentCandidate->getCandidateFields() (line 44 of /var/www/html/drupal/web/modules/contrib/entity_hierarchy/src/Information/ParentCandidate.php) #0 /var/www/html/drupal/web/modules/contrib/entity_hierarchy/src/Routing/ReorderChildrenAccess.php(69): Drupal\entity_hierarchy\Information\ParentCandidate->getCandidateFields('18') #1 [internal function]: Drupal\entity_hierarchy\Routing\ReorderChildrenAccess->access(Object(Symfony\Component\Routing\Route), NULL, Object(Drupal\Core\Session\AccountProxy)) #2 /var/www/html/drupal/web/core/lib/Drupal/Core/Access/AccessManager.php(159): call_user_func_array(Array, Array) #3 /var/www/html/drupal/web/core/lib/Drupal/Core/Access/AccessManager.php(135): Drupal\Core\Access\AccessManager->performCheck('access_check.en...', Object(Drupal\Component\Utility\ArgumentsResolver)) #4 /var/www/html/drupal/web/core/lib/Drupal/Core/Access/AccessManager.php(92): Drupal\Core\Access\AccessManager->check(Object(Drupal\Core\Routing\RouteMatch), Object(Drupal\Core\Session\AccountProxy), NULL, true) #5 /var/www/html/drupal/web/core/lib/Drupal/Core/Menu/LocalTaskManager.php(347): Drupal\Core\Access\AccessManager->checkNamedRoute('entity.node.ent...', Array, Object(Drupal\Core\Session\AccountProxy), true) #6 /var/www/html/drupal/web/core/lib/Drupal/Core/Menu/LocalTaskManager.php(378): Drupal\Core\Menu\LocalTaskManager->getTasksBuild('view.media_of.p...', Object(Drupal\Core\Cache\CacheableMetadata)) #7 /var/www/html/drupal/web/core/lib/Drupal/Core/Menu/Plugin/Block/LocalTasksBlock.php(95): Drupal\Core\Menu\LocalTaskManager->getLocalTasks('view.media_of.p...', 0) #8 /var/www/html/drupal/web/core/modules/block/src/BlockViewBuilder.php(203): Drupal\Core\Menu\Plugin\Block\LocalTasksBlock->build() #9 [internal function]: Drupal\block\BlockViewBuilder::preRender(Array) #10 /var/www/html/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(378): call_user_func('Drupal\\block\\Bl...', Array) #11 /var/www/html/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(450): Drupal\Core\Render\Renderer->doRender(Array) #12 /var/www/html/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(195): Drupal\Core\Render\Renderer->doRender(Array, false) #13 /var/www/html/drupal/web/core/lib/Drupal/Core/Template/TwigExtension.php(490): Drupal\Core\Render\Renderer->render(Array) #14 /var/www/html/drupal/web/sites/default/files/php/twig/5c6dfa6832a14_page.html.twig_bSBFdzJm9gjsbRg0uQYoaPOTU/bYnUK8TcZYKD6VVEMH-VidZX7CJS63otsbi2paUA1Qg.php(47): Drupal\Core\Template\TwigExtension->escapeFilter(Object(Drupal\Core\Template\TwigEnvironment), Array, 'html', NULL, true) #15 /var/www/html/drupal/vendor/twig/twig/lib/Twig/Template.php(428): __TwigTemplate_f8a17f041581af9829850fd45db45c2b69d8b3a60b80408d416da5d23dbccb61->doDisplay(Array, Array) #16 /var/www/html/drupal/vendor/twig/twig/lib/Twig/Template.php(399): Twig_Template->displayWithErrorHandling(Array, Array) #17 /var/www/html/drupal/vendor/twig/twig/lib/Twig/Template.php(407): Twig_Template->display(Array) #18 /var/www/html/drupal/web/core/themes/engines/twig/twig.engine(64): Twig_Template->render(Array) #19 /var/www/html/drupal/web/core/lib/Drupal/Core/Theme/ThemeManager.php(384): twig_render_template('core/themes/sev...', Array) #20 /var/www/html/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(437): Drupal\Core\Theme\ThemeManager->render('page', Array) #21 /var/www/html/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(195): Drupal\Core\Render\Renderer->doRender(Array, false) #22 /var/www/html/drupal/web/core/lib/Drupal/Core/Template/TwigExtension.php(490): Drupal\Core\Render\Renderer->render(Array) #23 /var/www/html/drupal/web/sites/default/files/php/twig/5c6dfa6832a14_html.html.twig_gQv-GORxUVif_Pag4s-5z2NkO/PT8lo6Q7QtqsQSkvBwYWa2seFwhmuK9ugVcYqIE_zP4.php(90): Drupal\Core\Template\TwigExtension->escapeFilter(Object(Drupal\Core\Template\TwigEnvironment), Array, 'html', NULL, true) #24 /var/www/html/drupal/vendor/twig/twig/lib/Twig/Template.php(428): __TwigTemplate_be8c7bbb9c824f2826368d7c8da984c6279779db72a67fd8056a00bb23b816f2->doDisplay(Array, Array) #25 /var/www/html/drupal/vendor/twig/twig/lib/Twig/Template.php(399): Twig_Template->displayWithErrorHandling(Array, Array) #26 /var/www/html/drupal/vendor/twig/twig/lib/Twig/Template.php(407): Twig_Template->display(Array) #27 /var/www/html/drupal/web/core/themes/engines/twig/twig.engine(64): Twig_Template->render(Array) #28 /var/www/html/drupal/web/core/lib/Drupal/Core/Theme/ThemeManager.php(384): twig_render_template('core/themes/cla...', Array) #29 /var/www/html/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(437): Drupal\Core\Theme\ThemeManager->render('html', Array) #30 /var/www/html/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(195): Drupal\Core\Render\Renderer->doRender(Array, false) #31 /var/www/html/drupal/web/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(147): Drupal\Core\Render\Renderer->render(Array) #32 /var/www/html/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(582): Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() #33 /var/www/html/drupal/web/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(148): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure)) #34 /var/www/html/drupal/web/core/lib/Drupal/Core/EventSubscriber/MainContentViewSubscriber.php(90): Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Routing\CurrentRouteMatch)) #35 [internal function]: Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object(Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent), 'kernel.view', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher)) #36 /var/www/html/drupal/web/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php(111): call_user_func(Array, Object(Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent), 'kernel.view', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher)) #37 /var/www/html/drupal/vendor/symfony/http-kernel/HttpKernel.php(156): Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('kernel.view', Object(Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent)) #38 /var/www/html/drupal/vendor/symfony/http-kernel/HttpKernel.php(68): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1) #39 /var/www/html/drupal/web/core/lib/Drupal/Core/StackMiddleware/Session.php(57): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #40 /var/www/html/drupal/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(47): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #41 /var/www/html/drupal/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(99): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #42 /var/www/html/drupal/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(78): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true) #43 /var/www/html/drupal/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(47): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #44 /var/www/html/drupal/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(52): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #45 /var/www/html/drupal/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #46 /var/www/html/drupal/web/core/lib/Drupal/Core/DrupalKernel.php(693): Stack\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #47 /var/www/html/drupal/web/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request)) #48 {main}.

In \Drupal\entity_hierarchy\Routing\ReorderChildrenAccess::access
receives entity=18 and fails. The route path in access() function is /node/{node}/children when node/18/media was requested.

Comments

jonathan_hunt created an issue. See original summary.

larowlan’s picture

Status: Active » Postponed (maintainer needs more info)

Hey @jonathan_hunt

We had something similar in #2918666: PHP error on reorder children page and I thought we had this behind us.

Clearly not.

Should the view be node/%node/media and not %media?

Lee

jonathan_hunt’s picture

Thanks for the quick response Lee.

The previous issue #2918666 appears to simply check that entity parameter exists, whereas the error in my case is that the parameter hasn't been processed from an identifier (18) to a full node. The view path is /node/%node/media which converts to /node/{node}/media in _route_object. Same behaviour for another view /node/%node/members.

In this case the entity_hierarchy is firing for a content type that doesn't even have children.

I'm still new to D8 but I wonder if entity_hierarchy is mixing up an access check for the specific node vs an access check for the specific route.

I wouldn't expect entity_hierarchy to have any opinion on /node/{node}/media, only /node/{node}/children but it's firing anyway...

[requirements:Symfony\Component\Routing\Route:private] => Array
(
[_entity_access] => node.view
[_permission] => reorder entity_hierarchy children
[_entity_hierarchy_has_field] => TRUE
)

larowlan’s picture

Yep, its expected - because drupal is access checking whether the local task needs to be shown on those pages.

I have seen this in workbench too, I'll see what we did there.

In the meantime, you can probably add an instance of check

jonathan_hunt’s picture

Ok, I see why that field check is made.

A nasty hack is

use Drupal\node\Entity\Node;
if (!is_object($entity) && $entity_type == 'node') {
  $entity = Node::load($entity);
}

That at least gets other paths rendering, but I'm sure there's a better fix...

larowlan’s picture

I suspect that views routes do things differently in their route definition.

->setOption('parameters', [
          $entity_type_id => ['type' => 'entity:' . $entity_type_id],
        ]);

My route definition has that so I get the upcasting, but not sure about the views one.

larowlan’s picture

According to https://drupal.stackexchange.com/a/229205 its views..
So I guess I need to handle that?

larowlan’s picture

What version of core are you using here? Speaking with views maintainers about whether there is a core bug here.

jonathan_hunt’s picture

8.6.10

larowlan’s picture

jonathan_hunt’s picture

Thanks Lee. /me watches #3034919

larowlan’s picture

betoaveiga’s picture

Version: 8.x-2.0 » 3.x-dev
StatusFileSize
new2.79 KB

I'm using this patch to avoid this type of error when loading a view.
From what I've read this doesn't fix the root issue but works by getting the ID of the entity and transforming that into the needed entity.
Hope that helps.

delacosta456’s picture

i am having the same issue on D9.2 and #13 is not working for me and make drush started complaining about error.

Can anybody help

? thanks

moshe weitzman’s picture

StatusFileSize
new2.81 KB

Reroll of #13 with with a type hint of EntityManagerInterface instead of EntityManager. This fixes an incompat with webprofiler module from devel.

larowlan’s picture

Status: Postponed (maintainer needs more info) » Needs review
larowlan’s picture

StatusFileSize
new3.21 KB

Expanded the comment and went with a check of the object class rather than the broad is_object

  • larowlan committed cd71318 on 3.x
    Issue #3034602 by larowlan, BetoAveiga, moshe weitzman, jonathan_hunt:...
larowlan’s picture

Status: Needs review » Fixed

Thanks, cutting 3.1.1

Status: Fixed » Closed (fixed)

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