Entity metadata wrappers

I recommend the use of Entity API for a number of reasons.  One reason is the Entity metadata wrapper.  Although I haven't actually used this, I can see its benefits, and plan to use it soon.  The Drupal Commerce set of modules makes extensive use of this.

What is allows is chainable access to all the properties of an entity.  For example, if you have a node, and wanted to find the node author's email address and change it, you could do this as follows:

$wrapper = entity_metadata_wrapper('node', $node);
$wrapper->author->mail->set('sepp@example.com'); (or just $wrapper->author->mail = 'sepp@example.com';

See http://drupal.org/node/1021556 for more details.


Add new comment