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.
Problem/Motivation
Config entity query is a little confused about case (in)sensitivity. This code should return the 'Content' view (from the standard profile) among the results, but it doesn't.
$query = \Drupal::entityQuery('view');
$query->condition('label', 'c', 'CONTAINS');
$result = $query->execute();
debug($result);
Proposed resolution
I assume that the condition value is lowercased before doing the comparison, but the actual values that it's checked against are not.
Remaining tasks
Investigate, propose a resolution.
User interface changes
None.
API changes
Not sure.
Related Issues
#2068655: Entity fields do not support case sensitive queries
Comment | File | Size | Author |
---|---|---|---|
#4 | 2107309-4.patch | 6.9 KB | amateescu |
#4 | interdiff.txt | 5 KB | amateescu |
#1 | 2107309-test-only.patch | 1.41 KB | amateescu |
#1 | 2107309.patch | 2.89 KB | amateescu |
Comments
Comment #1
amateescu CreditAttribution: amateescu commentedThis should do it.
Comment #2
dawehner\Drupal\Core\Entity\QueryInterface::condition should document that the value is case-insensitive.
Comment #4
amateescu CreditAttribution: amateescu commentedFixed those test fails and documented the case-insensitivity aspect.
Comment #5
damiankloip CreditAttribution: damiankloip commentedwhat do you think about all of this logic living in match? Then it's all in one place.
Apart from that, this looks good to me!
Comment #6
amateescu CreditAttribution: amateescu commentedI deliberately put them in separate places for performance reasons.
The condition array stays the same for the duration of the matching process, so it makes sense to update it as early as possible, while the match() method is invoked multiple times, but not for every property of the config entity, so it doesn't make sense to do the lowercase transformation on all values of the entity.
Comment #7
damiankloip CreditAttribution: damiankloip commentedWe talked about this on IRC, it makes sense to do the transformation in compile() for sure.
Has tests and the rest of the code looks good , so RTBC.
chx, this should get your attention anyway :)
Comment #8
chx CreditAttribution: chx commentedThis will be fine. (It doesn't get my attention. I no longer monitor the RTBC queue.)
Comment #9
catchCommitted/pushed to 8.x, thanks!
Comment #10.0
(not verified) CreditAttribution: commentedUpdated wrong example.