Closed (fixed)
Project:
Mailchimp
Version:
8.x-1.x-dev
Component:
Campaign Module
Priority:
Normal
Category:
Bug report
Assigned:
Reporter:
Created:
7 Aug 2019 at 14:40 UTC
Updated:
1 Jan 2021 at 01:54 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
tаo commentedComment #3
samuel.mortensonThis doesn't quite make sense to me - not all PHP objects have a
render()method, so is there an interface we should be checking here instead?Comment #4
firfin commentedI ran into this with the email variable which is added in mailchimp_get_mergevars() as
'name' => t('Email Address'),So then ->name contains a TranslatableMarkup. In this case 'render'ing it makes sense?Also this is on the only time an object *should* be returned as the ->name. The rest of the merge_vars come from the Mailchimp API using the function getMergeFields. This function returns only string for the 'name' parameter as per https://mailchimp.com/developer/reference/lists/list-merges/#read-get_li...
Patch in #1 is a much more constructive solution than I would have made. Which would be just adding an is_scalar() in buildMergeVarsHtml() to check $var->name before trying to use it as an array key. And hence not being able to use the email at all.
Unfortunately the path did not apply on 8.x-DEV, so made a re-roll (also updated the array() notation, that was why patch from #2 failed)
Comment #5
firfin commentedComment #6
firfin commentedThe patch
Comment #7
vladimirausWorks on the latest dev branch.
Please commit.
Comment #8
brendanthinkshout commentedLong comment here, but I'm rubber-ducking this patch to myself to make sure it makes sense. I think Sam's initial hesitation is a good one--determining that we have ended up with an object in a mergevar is not a future-proof guarantee that the object will be renderable. The original cause of the error is that we're trying to index an array with an object, when we actually need a type that is a valid array key. But it's still fine to pass a TranslatableMarkup object in as the value in a markup item.
For these reasons, I added a check for the more general __toString magic method, which TranslatableMarkup implements through ToStringTrait. My understanding is that casting
strval()on a TranslatableArray should get us the rendered value anyway, but with a check that's less dependent on the render method specifically.If there is a change to the API/library such that we end up with a non-renderable object in the merge, we have three choices: ignore it and silently continue the loop; run a try/catch and surface the error in a nonfatal way; or throw an uncaught warning, so basically what we had before. Try/catch seems like expensive overkill and I don't want to bury a breaking change like that, so I think the third option is probably best for this case, and would ideally lead back to this issue for context on a search.
firfin, if you can try this patch with the case you described in #4 I'd really appreciate it. VladimirAus, if you have a similar test case your review would be helpful as well.
Comment #9
gcbComment #13
gcb