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->value();
$wrapper->author->mail->set('sepp@example.com'); (or just $wrapper->author->mail = 'sepp@example.com';

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

Tags: 

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.