entityQuery: When compared against an array, such as categories condition in webform, Drupal crashes

Created on 25 October 2023, about 1 year ago
Updated 19 August 2024, 3 months ago

Problem/Motivation

There are two problems here, both of them in Drupal\Core\Config\Entity\Query\Condition.php.

This occurs under the condition that there are array values stored for a property in a config entity. In order to match the comparison correctly, the entity query system needs modification.

  1. There's a conversion to lower case that fails since it can't take an array as input.
  2. There's no comparison of a single value against an array value. The opposite exists, there a comparison with $condition['value'], but it matches the opposite, comparing an array in the condition with a mixed value in entity config.

The error given is:
TypeError: mb_strtolower(): Argument #1 ($string) must be of type string, array given in mb_strtolower() (line 174 of core/lib/Drupal/Core/Config/Entity/Query/Condition.php). Drupal\Core\Config\Entity\Query\Condition->match(Array, Array) (Line: 145)

Steps to reproduce

  1. Install webform and import the sample form attached, notice there are two categories present in the config.
  2. Set up a module that extracts entities from webform, filtered by the presence of a category. Sample code is given below.

Comparison code:

    $webforms = \Drupal::entityQuery('webform')
      ->accessCheck(FALSE)
      ->condition('categories', 'sample_category_1')
      ->execute();

Proposed resolution

When there's a match against the array value in entity config, the entityQuery should return all matching entities.

Remaining tasks

User interface changes

None

API changes

None

Data model changes

None

Release notes snippet

🐛 Bug report
Status

Needs work

Version

11.0 🔥

Component
Entity 

Last updated about 21 hours ago

Created by

🇳🇴Norway svenryen

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

Merge Requests

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