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.
Beta phase evaluation
Issue category | Bug because it shows a PHP error warning |
---|---|
Issue priority | Major because it is a non-fatal PHP error, or a PHP error triggered under rare circumstances or affecting only a small percentage of all users. | Unfrozen changes | Unfrozen because it fixes a bug |
Problem/Motivation
Follow-up of #2546210: Views subtokens are broken since the introduction of inline templates for replacements
Warning: strlen() expects parameter 1 to be string, array given in Drupal\Component\Utility\Unicode::validateUtf8()
This error is thrown when using any link field token in a view.
In \Drupal\views\Plugin\views\field\Field::addSelfTokens() is_scalar is only checked for the value when the parent item is an array, not when it's an object.
Proposed resolution
Add check when parent item is an object.
Remaining tasks
- Add more link token tests?
Comment | File | Size | Author |
---|---|---|---|
#40 | 2567339-40.patch | 10.29 KB | Lendude |
#40 | interdiff-2567339-37-40.txt | 2.14 KB | Lendude |
#37 | 2567339-37.patch | 10.17 KB | Lendude |
#37 | interdif-2567339-35-37.txt | 1001 bytes | Lendude |
#35 | 2567339-35.patch | 10.18 KB | Lendude |
Comments
Comment #2
LendudeTest only and patch for it.
Comment #5
LendudeComment #6
cilefen CreditAttribution: cilefen commentedThe bug is actually in the views module according to the patch.
Comment #7
LendudeCleaned up the test a bit, and now it actually tests something.
Comment #8
dawehnerI think we no longer needs tests, yeaah!
It would be great to have some quick comment, why we need this check here.
Comment #9
Lendudeas per #8, added/changed comments.
Comment #10
LendudeOnce #2488540: Rewrite external links in views fields is in, I think we might need to add a task to test some more scenarios, or if this gets in first, expand the test coverage in #2488540: Rewrite external links in views fields
Comment #11
dawehnerThis for now solves a problem.
Comment #16
Lenduderandom fails, back to RTBC
Comment #19
LendudeRandom test fail, back to RTBC
Comment #22
LendudeMore random test fails, back to RTBC
Comment #25
LendudeRandom test fail, back to RTBC
Comment #26
alexpottWhy is $property->getValue() returning an object and if said object implements __toString() is it not okay?
Comment #27
Lendude$property->getValue() is returning an array in the case of the link token for {{ field_link__options }}. So no really good way to convert that to a string that I can see (beside imploding it on an arbitrary delimiter).
Not sure if $property->getValue() ever returns an object, but I guess checking for that and __toString() is an option. Added that to the patch.
Comment #28
penyaskitoEdited the content view and played around with tokens for reproducing the issue.
Did the same with the patch applied and the error disappears.
Last patch resolves concerns at #26, so I think we can set it back to RTBC.
Added beta evaluation template.
Comment #29
catchIs that a valid return value for the link token though?
Comment #30
LendudeUpdated the issue summary a bit, to make it clear that the problem comes form the parent item being an array or an object, not the actual return value.
There are checks in place to sanitize/discard the return value when the parent item is an array that are not in place when the parent item is an object.
Also the comment above this bit of code states:
So as to what we can expect here it's apparently all a bit of a guess.
Does that answer your question? Or were you referring to something else?
Comment #31
rootworkJust wanted to confirm that #27 does apply and fix the problem, as of RC1. Not sure about catch's question in #29 though but hoping to see this move forward.
Comment #32
LendudeTalked to @catch about this on IRC a while ago, and he was really wondering about the bit
We know nothing about the data
and why that is. Didn't have an answer for him.
Comment #33
dawehnerTalked with fago today. We should check whether these things are primitive items ... in which case we know how to render them.
Comment #34
dawehnerBack to needs work
Comment #35
LendudeNow checking if TypedDataInterface is used and the just calling getString on that. Will check with @fago if this should be done safer and check for PrimitiveBase instead.
But for now lets see what this does.
Comment #36
Lendudetalked to @fago and he told me using the TypedDataInterface is fine.
Comment #37
LendudeProper order of the use statements and removed some newlines.
Comment #38
ultimikeI hit this issue and tried out the patch in comment 37 and it fixed my issue.
thanks,
-mike
Comment #39
dawehnerThank you @lendude!!
here are a couple of nitpicks / one small remark on the test.
I like this solution now!
Let's just use camelcase ...
netpick: let's use
{@inheritdoc}
Nitpicks: Let's use public here.
Let's fill out options to ensure that also maps are filled out properly. Those fields also have a
getString()
implementation.Comment #40
Lendude@dawehner thanks for the review!
1. fixed
2. fixed
3. fixed
4. Filled the options setting and the settings get applied as you can see in the test. But the options still come back as an empty string. This is because on $values get set in the Map and not properties. I don't know if I need to set it in a different way or that there is something else going on. Since there seems to be no way to set 'options' through the UI (at least none that I could find), I'm not sure what it expects.
Comment #41
jibranLooks ready to me. Just one question.
Do we need an update function to fix this for all the existing views using this token?
Comment #42
mikeker CreditAttribution: mikeker as a volunteer commentedI don't believe so. The token doesn't change, just the value that replaces it.
Comment #43
dawehnerYeah, right. Let's try to not overthing update paths.
Comment #44
jibranOk then.
Comment #46
Lendudetestbot glitch
Comment #48
Lendudeuhh it's still green, not sure why it says it failed...
Comment #49
alexpottWhat is the point of having a token that can't ever be displayed? Do we need to handle this better?
Comment #50
dawehnerIMHO this is out of scope of this issue. This is just about fixing the field tokens itself, while your request is about fixing the general token functionality in views, IMHO.
Here is a follow up: #2657024: Hide non existing views tokens
Comment #51
LendudeI agree with @dawehner that this feel like a bit of a scope creep to fix that here.
That said, I was surprised that the token stayed empty after adding some settings like I pointed out in #40.4, so I could totally get behind updating the comment to indicate that an empty sting this is not the expected behaviour for that token and referencing the issue that dawehner created.
Comment #52
alexpott@dawehner thanks for creating #2657024: Hide non existing views tokens - I think if a token can't be made into a string then it can't be a token right... seems very wrong.
Committed ba13b1b and pushed to 8.0.x and 8.1.x. Thanks!