Hi, I ran into an issue where mailchimp_lists_load_email fails to load the email address when the email field is stored against a related entity.
For example, instead of applying Mailchimp Subscription field to the user profile directly, it's instead applied to an entity which references the user profile. I can configure/save this without any issues, but when I try and display the field an error occurs as the field cannot be found.
This seems to happen as the $mail_property variable contains a path to the referenced entity (eg 'uid:entity:mail') which can't be handled when calling $entity::get (on line 118 of mailchimp_lists.module).
My quick/dirty hack is to check if the property contains a colon character, and if so manually traverses the object graph (see attached patch), but I'm sure there's probably a better way to handle this.
Let me know if you need any further info.
| Comment | File | Size | Author |
|---|---|---|---|
| #14 | mailchimp-entity-traversal-2949125-12.patch | 6.55 KB | reinfate |
| #11 | mailchimp-entity-traversal-2949125-11.patch | 6.51 KB | aprice42 |
| #10 | mailchimp-entity-traversal-2949125-10.patch | 6.47 KB | aprice42 |
| #5 | entity_traversal-2949125-5.patch | 4.86 KB | rjacobsen0 |
| #3 | entity_traversal-2949125-3.patch | 1.12 KB | yanniboi |
Comments
Comment #2
yanniboi commentedYup, I can confirm this issue. I think ideally we want to have a default way for traversing entity relationships (such as entity reference fields) similar to
\Drupal\Core\Entity\Query\Sql\Table::addField()(https://www.drupal.org/node/2825947). I don't know off the top of my head if there is already a way of doing this in Drupal core, but I feel like there should be.Comment #3
yanniboi commentedHmmm there is something wrong with the formating of that patch. It doesnt apply for me.
Uploading it again.
Comment #4
samuel.mortensonComment #5
rjacobsen0 commentedIt's less a hack if the code for dereferencing the entity is next to the code that builds the list of options. I put them both in class MailchimpListsSubscription. I also ran into a bug where I was able to delete a field and because it was the chosen email an error was thrown. Catching it and assigning null in that case.
Comment #6
samuel.mortensonLots of review, mostly coding standard related:
I think we should either rename this method to "addOptionsForSubEntity" and have it take in
$optionsas a reference, or keep the name but instead of being passed options, have it return FALSE if no bundle could be found, or the options to be appended to$options.Doc here needs fleshed out.
Per Drupal coding standards, opening curly braces should be on the same line as the function/method declaration. Also all the new code should use two spaces, not four.
Per coding standards "Inline comments must start with a capital letter". Also should be less than 80 characters.
Need a space between (string) and $label here.
Only one blank space between methods is required/standard.
Doc needs fleshed out here.
The curly brace needs moved, the method name should start with a lowercase letter, and the method should be private.
Just barely over 80 characters here.
It looks like my IDE is reading this docblock correctly, but typically the variable name comes after the class name - i.e. "@var \Foo $foo"
Should we be doing a try/catch here as well?
$accessorisn't necessarily set on$entity.Drupal coding standards have "else" always appearing on its own line.
In the Drupal coding standards FALSE, TRUE, and NULL are always uppercase. Also we should make sure to update the docblock to reflect that NULL can be returned from this method.
Comment #7
samuel.mortensonComment #8
enrega commentedThe patch in #5 doesn't apply to the current dev version of the module. Can the patch be updated please?
Comment #9
gcbComment #10
aprice42 commentedRerolled patch and made requested changes.
Comment #11
aprice42 commentedReverting the change to making getMailField private, as it needs to be public for this usage.
Comment #12
aprice42 commentedThere is something broken here. Not totally clear about what is supposed to happen, but it definitely feels like setting $mail_field to the $entity value, and then changing that value in the foreach is creating one issue, but if this was working, then I am confused how/why it was.
Comment #13
mrdalesmith commentedHit this issue and the latest patch resolves it for me.
Comment #14
reinfate commentedThe last patch produces a warning if one of the field ancestors is NULL. For example, if the entity is only being created and the reference field is not set yet.
Fixed it by adding a simple check at the line 136 in the patch
Comment #15
aprice42 commentedComment #19
xenophyle commented