Calling methods hasAllTags / hasAnyTag on entity queries fails if query has no tag

Created on 7 February 2023, almost 2 years ago
Updated 21 June 2023, over 1 year ago

Problem/Motivation

Calling one of the methods hasAllTags or hasAnyTag on entity queries throws an error if no tags have been added to the query since the alterTags property is not initialized with an empty array.

TypeError: array_keys(): Argument #1 ($array) must be of type array, null given in /home/proettger/sites/swhd/web/core/lib/Drupal/Core/Entity/Query/QueryBase.php

Steps to reproduce

Run the following snippet in the codebase:

$query = \Drupal::entityQuery('node');
$query->hasAnyTag(['foo', 'bar']);

Proposed resolution

Initialize the alterTags property with an empty array.

Remaining tasks

  • Review patch
  • Write a test
🐛 Bug report
Status

Needs work

Version

11.0 🔥

Component
Entity 

Last updated about 11 hours ago

Created by

🇩🇪Germany Patrick R.

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024