Problem/Motivation

Currently mailchimp_lists_rules_action_entity_subscribe() uses $entity->raw() as parameter to call mailchimp_lists_process_subscribe_form_choices().
Unfortunately this can be the id of the entity and not the entity object.

Proposed resolution

Use $entity->value() this should always provide the unwrapped entity.

Remaining tasks

Reviews needed.

User interface changes

None.

API changes

None.

Data model changes

None.

Comments

BabaYaga64’s picture

Status: Needs review » Postponed (maintainer needs more info)

From what I understand, it seems that $entity->raw() and $entity->value() both return correct entity object ids. The difference is that $entity->raw() provides the raw data, and $entity->value() provides the wrapped data. I haven't been able to reproduce this issue so that I can check to see if your patch works. Would it be possible for you to provide documentation for $entity->raw() returning the entity id and not the entity object id? Or perhaps suggest a way to reproduce the behavior you're describing?

das-peter’s picture

Status: Postponed (maintainer needs more info) » Needs review

Thanks for the feedback :)
Fired up my debugger again.
The only "special" thing in my case is, that I use an item list in rules.
This means that entity is actually an EntityListWrapper item, which seems to return the id when using raw() and the object when using value().
However, my suggestion stands:
While raw() seems to return "inconsistent" values, value() doesn't. And as of my experience and tests value() shouldn't return a wrapped entity, it might processes the output, e.g formatting a date when accessing a date field, but it doesn't wrap the data in an entity metadata wrapper.
Test-Code:

$nid = 'your_nid';
// Enity list handler.
entity_metadata_wrapper('list<node>', array(node_load($nid)))[0]->raw(); // integer = $nid
entity_metadata_wrapper('list<node>', array(node_load($nid)))[0]->value(); // stdClass - no metadata wrapper.
// Entity handler.
entity_metadata_wrapper('node', $nid)->value(); // stdClass - no metadata wrapper.
entity_metadata_wrapper('node', $nid)->raw(); // stdClass - no metadata wrapper.

// Another check of value().
entity_metadata_wrapper('node', $nid)->body; // value wrapper.
entity_metadata_wrapper('node', $nid)->body->value(); // The body value.
entity_metadata_wrapper('node', $nid)->body->raw(); // The unprocessed body value.
BabaYaga64’s picture

Status: Needs review » Reviewed & tested by the community

Das-Peter, I've applied and tested your patch, and it works! I'm waiting to push the changes to the mailchimp repo until I get clearance from my colleague. Thank you!

das-peter’s picture

@BabaYaga64 Awesome, thanks :) I very much appreciate your fantastic reaction time!!

jami’s picture

Version: 7.x-3.x-dev » 7.x-3.4
Status: Reviewed & tested by the community » Fixed

Pushed to 7.x-3.x.
http://drupalcode.org/project/mailchimp.git/commit/29419b0

Thanks for your work das-peter and BabaYaga64!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.