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

Issue fork drupal-3557953

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

alexdoma created an issue. See original summary.

alexdoma’s picture

Issue summary: View changes

harivansh made their first commit to this issue’s fork.

quietone’s picture

Version: 11.1.x-dev » 11.x-dev

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

souvik_banerjee made their first commit to this issue’s fork.

souvik_banerjee’s picture

Status: Active » Needs review

I have added MR for this and its working for me, please check!

smustgrave’s picture

Status: Needs review » Needs work

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

alexdoma’s picture

Empty $display['display_options']['filters'] was in views related to rss

alexdoma’s picture

Issue summary: View changes
souvik_banerjee’s picture

Status: Needs work » Needs review

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

smustgrave’s picture

Status: Needs review » Needs work

If it’s a bad view configuration what caused that? Was it a bad update hook? Should a default be set

alexdoma’s picture

this warning appears after migration to drupal 11 from drupal 10.

acbramley made their first commit to this issue’s fork.

acbramley’s picture

Status: Needs work » Needs review

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

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

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

quietone’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs title update

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

acbramley’s picture

Title: Warning: foreach() argument must be of type array|object, null given in Drupal\node\Hook\NodeRequirements->runtime() » Drupal\node\Hook\NodeRequirements::runtime throws PHP warning when views filters are NULL
Status: Needs work » Reviewed & tested by the community
Issue tags: -Needs title update

  • catch committed e51b3809 on 11.x
    fix: #3557953 Drupal\node\Hook\NodeRequirements::runtime throws PHP...

  • catch committed 98539c4b on main
    fix: #3557953 Drupal\node\Hook\NodeRequirements::runtime throws PHP...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Given 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!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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