Problem/Motivation
Warning on admin/reports/status
This warning is result of https://www.drupal.org/node/3472976 and https://www.drupal.org/node/3449181
https://git.drupalcode.org/project/drupal/-/merge_requests/8156/diffs#a3...
Warning: foreach() argument must be of type array|object, null given in Drupal\node\Hook\NodeRequirements->runtime() (line 72 of core/modules/node/src/Hook/NodeRequirements.php).
Drupal\node\Hook\NodeRequirements->runtime()
call_user_func_array() (Line: 404)
Drupal\Core\Extension\ModuleHandler->Drupal\Core\Extension\{closure}() (Line: 357)
Drupal\Core\Extension\ModuleHandler->invokeAllWith() (Line: 403)
Drupal\Core\Extension\ModuleHandler->invokeAll() (Line: 129)
Drupal\system\SystemManager->listRequirements() (Line: 53)
Drupal\system\Controller\SystemInfoController->status()
call_user_func_array() (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 627)
Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 121)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext() (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 183)
Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 53)
Drupal\Core\StackMiddleware\Session->handle() (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 28)
Drupal\Core\StackMiddleware\ContentLength->handle() (Line: 116)
Drupal\page_cache\StackMiddleware\PageCache->pass() (Line: 90)
Drupal\page_cache\StackMiddleware\PageCache->handle() (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 53)
Drupal\Core\StackMiddleware\AjaxPageState->handle() (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle() (Line: 715)
Drupal\Core\DrupalKernel->handle() (Line: 19)
Steps to reproduce
Project should have Views with $display['display_options']['filters'] === NULL
Empty $display['display_options']['filters'] was in views related to rss
Proposed resolution
add condition - is_array($display['display_options']['filters'])
$views_storage = $this->entityTypeManager->getStorage('view');
foreach ($views_storage->loadMultiple($active_view_ids) as $view) {
foreach ($view->get('display') as $display_id => $display) {
if (array_key_exists('filters', $display['display_options']) && is_array($display['display_options']['filters'])) {
foreach ($display['display_options']['filters'] as $filter) {
if (array_key_exists('plugin_id', $filter) && $filter['plugin_id'] === 'node_status') {
$node_status_filter_problematic_views[$view->id()][$display_id] = [
'view_label' => $view->label(),
'display_name' => $display['display_title'] ?? $display_id,
];
break;
}
}
}
}
}
Remaining tasks
User interface changes
Introduced terminology
API changes
Data model changes
Release notes snippet
Comments
Comment #2
alexdoma commentedComment #4
quietone commentedHi, in Drupal core changes are made on on 11.x (our main development branch) first, and are then back ported as needed according to the Core change policies. Thanks.
Comment #7
souvik_banerjee commentedI have added MR for this and its working for me, please check!
Comment #8
smustgrave commentedSo tickets like these typically need research about where a value is not getting set. Just putting an isset() or empty() check could mask a larger issue.
Should have test coverage potentially too.
Comment #9
alexdoma commentedEmpty $display['display_options']['filters'] was in views related to rss
Comment #10
alexdoma commentedComment #11
souvik_banerjee commented@smustgrave I have added the test coverage. I understand that using checks like isset() or empty() may only treat the symptoms instead of fixing the real issue. I found that this problem occurs because of an incorrect views configuration, and I think core should have a check to prevent this so it doesn’t affect the status report like it does here.
Do you see any other place where we can fix this properly?
Comment #12
smustgrave commentedIf it’s a bad view configuration what caused that? Was it a bad update hook? Should a default be set
Comment #13
alexdoma commentedthis warning appears after migration to drupal 11 from drupal 10.
Comment #15
acbramley commentedIdeally we'd know what upgrade path exactly caused this but I can't see anything in ViewsConfigUpdater (on HEAD at least) that would set filters to NULL. I'm not sure it's worth trying to track that down tbh, it seems to be affecting a few people and the fix is straightforward.
Simplified some of the logic and changed the test to only set
$this->strictConfigSchema = FALSE;for our specific test case.Comment #16
smustgrave commentedWe kinda experienced this on better_exposed_filters for views that have 0 filters, think this is good defensive code. Though at this point may not help but so many.
Comment #17
quietone commentedThe title here needs context, a developer reading the commit log should have more information about this change. In particular, it is related to the upgrade path and ViewsConfigUpdater.
Comment #18
acbramley commentedComment #21
catchGiven this logic only builds the requirements message I think it's OK to be defensive, if we need to show errors about null filters that could happen elsewhere.
Committed/pushed to main and 11.x, thanks!