Problem/Motivation
When doing a simple EQ on a top-level array property of a config entity, this warning is given:
<b>Warning</b>: mb_strtolower() expects parameter 1 to be string, array given in <b>/home/andrei/work/d8.dev/core/lib/Drupal/Component/Utility/Unicode.php</b> on line <b>295</b>
Proposed resolution
Fix it :)
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | 2248567-9-do-not-test.patch | 3.04 KB | amateescu |
Comments
Comment #1
amateescu commentedHere's a test-only patch that shows the problem.
Comment #2
amateescu commentedScratch that, the test data has to be even simpler.
Comment #4
amateescu commentedThat test class makes it sooo difficult to add something to it without having to update all the assertions. This one should be more clear about the bug at hand.
Comment #7
amateescu commentedOk, nevermind me, the
property.*syntax seems to work.Comment #8
amateescu commentedDiscussed a bit with chx. Doing this would mean we need to load config schemas to know that the condition field holds an array.
Comment #9
amateescu commentedAnd here's a first shot at it, also from chx. Tested locally and not fully working, but it's a start at least :)
Comment #10
chx commentedThe title is wrong: content entities can't do this because content entities can't store an array. It is sensible that a
foo: [1, 2, 3]be matched withcondition('foo', 1)that's for sure but there's nothing similar in content entities .Comment #11
berdirWell, content entities don't have arrays, but they have list of values, condition('tags.target_id', 5) with a multi-value tags reference field is a very similar situation as far as the API is concerned?
Comment #12
chx commentedThere's a huge difference between $node->field[0]->target_id $node->field[1]->target_id and foo: [1, 2, 3]. Once again: the expectation is expected :) so this might be a bug but there's nothing in content mirroring this.
Comment #13
chx commentedComment #14
chx commentedComment #21
pfrenssenTo make it clear, here is the correct way of adding an array condition to an entity query for a config entity.
This is wrong, it throws "mb_strtolower() expects parameter 1 to be string, array given":
Instead do this:
Comment #22
hchonov@pfrenssen, thank you for providing the example.
However it is very confusing for developers if an entity query for content entities and config entities has to be used differently when searching for a value in an array (config entities) / multiple field (content entities). I think that we could offer an consistent way for such queries.
Comment #23
jhedstromI wonder if an
assertcould be added somewhere to provide better feedback to developers if the incorrect approach outlined in #21 is used instead of the correct approach (eg, assert the value is a string not an array.)Comment #26
hadros commented@pfrenssen thanks man