Navigating your Entity Metadata Wrapper
For those of you who haven't worked with Entity Metadata Wrapper in Drupal before, drop the burrito visit the documentation page on Drupal.org https://www.drupal.org/node/1021556.
Entity Metadata Wrapper takes working with render arrays from blah, to "yeah!" in seconds. For instance, remeber how painful it was to get the file url out of an image field before:
$image_uri = $variables['field_svg']['uri']; $image_url = file_create_url($image_uri);
Ok... not excruciating, but not fun either. What would be fun is if our object were smart enough to just give us the url without us having to generate it each time. Something like this:
$image_url = $node_wrapper->field_svg->file->url->value();
And remember when you wanted to access information about an article that is referenced by another article you had to write this:
$referenced_article = node_load($node->field_arcticle_ref['target_id']); $referenced_article_title = $referenced_article->title;
Wouldn't it make more sense to just write:
$image_url = $node_wrapper->field_article_ref->title->value();
Well that's the magic of Entity Metadata Wrapper. And I'm not even stratching the surface. The real power surfaces when you start updating data within those objects!
But one problem arises; how do we know what information we have access to when using Entity Metadata Wrapper on our objects? In this video I'll show you how to use the entity method 'getPropertyInfo()' to inspect those objects within Entity Metadata Wrapper.