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.
Hello,
When I do a cache rebuild I get an error called
Warning: Invalid argument supplied for foreach() in Drupal\Component\Plugin\Discovery\DerivativeDiscoveryDecorator->getDerivatives() (line 102 of core/lib/Drupal/Component/Plugin/Discovery/DerivativeDiscoveryDecorator.php).
Drupal\Component\Plugin\Discovery\DerivativeDiscoveryDecorator->getDerivatives(Array) (Line: 87)
Drupal\Component\Plugin\Discovery\DerivativeDiscoveryDecorator->getDefinitions() (Line: 283)
Drupal\Core\Plugin\DefaultPluginManager->findDefinitions() (Line: 174)
Drupal\Core\Plugin\DefaultPluginManager->getDefinitions() (Line: 181)
Drupal\Core\Menu\LocalTaskManager->getDefinitions() (Line: 206)
Drupal\Core\Menu\LocalTaskManager->getLocalTasksForRoute('system.performance_settings') (Line: 290)
Drupal\Core\Menu\LocalTaskManager->getTasksBuild('system.performance_settings', Object) (Line: 358)
Drupal\Core\Menu\LocalTaskManager->getLocalTasks('system.performance_settings', 0) (Line: 94)
Drupal\Core\Menu\Plugin\Block\LocalTasksBlock->build() (Line: 203)
Drupal\block\BlockViewBuilder::preRender(Array)
call_user_func('Drupal\block\BlockViewBuilder::preRender', Array) (Line: 376)
Drupal\Core\Render\Renderer->doRender(Array) (Line: 448)
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: 47)
__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: 435)
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: 435)
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: 574)
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) (Line: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('kernel.view', Object) (Line: 149)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 64)
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: 656)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
It looks like it gets an empty object into a foreach loop. I fixed it with an empty check in the core, attached is the patch.
Comment | File | Size | Author |
---|---|---|---|
#27 | interdiff_26-27.txt | 830 bytes | pooja saraah |
#27 | 2893892-27.patch | 2.28 KB | pooja saraah |
#26 | 2893892-26.patch | 2.29 KB | priya.chat |
#19 | 2893892-19.patch | 2.21 KB | raman.b |
#19 | interdiff_11-19.txt | 1.14 KB | raman.b |
Comments
Comment #3
Rajab Natshah CreditAttribution: Rajab Natshah at Vardot commentedDo we have any updated about this issue?
Comment #5
renatogI applied the patch and works good for me.
Good Work and Good Weekend.
Best,
Comment #6
alexpottIt should not be necessary to check the emptiness here.
According to the docs in
\Drupal\Component\Plugin\Derivative\DeriverInterface::getDerivativeDefinitions()
(see below)$derivative_definitions
should always be an array. We need to work out why it is not. What are the steps to reproduce the problem? What contrib modules are installed?Comment #7
Dinesh18 CreditAttribution: Dinesh18 as a volunteer commented$derivative_definitions is an array as per the documentation. I have reviewed the patch file and it seems,which returns an array called
$derivative_definitions from
$deriver->getDerivativeDefinitions($plugin_definition);
We have used foreach for derivative_definitions to look for each definition.
Here is the interdiff which removes the
if(!empty($derivative_definitions))
Comment #8
borisson_#7 is just an interdiff, we need to have the patch as well, so maintainers don't need to apply both files.
Comment #10
Ben Coleman CreditAttribution: Ben Coleman commentedWell, all the #7 interdiff does is revert back to the pre-patch state. Might as well just say don't use the patch.
We're running into the same problem on a Drupal 8.6 site, every time a node is changed via the UI.
Comment #11
gngn CreditAttribution: gngn at Computer Manufaktur GmbH commentedI agree with alexpott (#6) and Dinesh18 (#7) that
but not with their conclusion
Some modules (e.g.older version of ldap) fail to return an array (at least an empty one).
So in order to need to "work out why it is not" I think it would be better to test if $derivative_definitions is an array (an empty one is OK in foreach) and may be log a warning containing $base_plugin_id.
This way we know which module is responsible and can take action (and get rid of the PHP warning).
Patch attached (maybe we need dependency injection to use the logger?)
Comment #12
collinhaines CreditAttribution: collinhaines commentedHad the same issue where this error was appearing after a cache clearing/rebuilding. Applied the patch in #11 and the error has not appeared since.
Comment #13
renatogI agree with @collinhaimes
Also works good for me
+1 to it
Comment #14
alexpottI think a trigger_error(E_USER_WARNING) is appropriate here. And let that do the logging. Then we don't have a call out to a service in the a component library.
Bring on strict types and return types in PHP7!
Comment #15
alexpottAlso tbh we are replacing a warning with a warning so /shrug - is this really worth it? Make for the extra info but still.
Comment #18
DuneBLJust to say that this log help me to debug a stupid error (forgot to return the famous array).
Working well... missing DI
Comment #19
raman.b CreditAttribution: raman.b at OpenSense Labs commentedNot sure how relevant this is. But adding patch to use
trigger_error
as per #14.Comment #24
borisson_This is a really good question that is hard to answer, I think the more specific error here is better, so I'd give this a +1
This comment goes over 80 chars wide, should be reflowed. It also probably needs to start with a capital letter.
Comment #25
SpokjeBesides the comment issue mention by @borisson_ in #24
core/lib/Drupal/Component/Plugin/Discovery/DerivativeDiscoveryDecorator.php
also changes from 644 to 755 and that displeases TestBot:Comment #26
priya.chat CreditAttribution: priya.chat as a volunteer and at TO THE NEW for TO THE NEW commentedHi All, thanks for looking into this issue. I am also trying to help here.
I have made few changes in patch #11, as added one more check for array count.
Also, as suggested by @borisson_ in #24 , I have corrected the comment line. this may help.
Comment #27
pooja saraah CreditAttribution: pooja saraah at Srijan | A Material+ Company for Drupal India Association commentedFixed Failed Commands on #26
Attached interdiff
Comment #29
smustgrave CreditAttribution: smustgrave at Mobomo commentedThis issue is being reviewed by the kind folks in Slack, #need-reveiw-queue. We are working to keep the size of Needs Review queue [2700+ issues] to around 200, following Review a patch or merge require as a guide.
Moving back to NW for an issue summary update as the solution appears to be add a more detailed log which isn't mentioned in the IS.
Also think this will need a test case