Created
October 9, 2012 09:51
-
-
Save guoxiangke/3857700 to your computer and use it in GitHub Desktop.
Entity metadata wrappers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Create wrapper around the node. | |
$wrapper = entity_metadata_wrapper('node', $node); | |
// We can do it also using only $nid. | |
$wrapper = entity_metadata_wrapper('node', $nid); | |
// Get the value of field_name of the nodes author's profile. | |
$wrapper->author->profile->field_name->value(); | |
$wrapper->author->profile->field_name->set('New name'); | |
// Value of the node's summary in german language. | |
$wrapper->language('de')->body->summary->value(); | |
// Check whether we can edit node's author email address. | |
$wrapper->author->mail->access('edit') ? TRUE : FALSE; | |
// Get roles of node's author. | |
$wrapper->author->roles->optionsList(); | |
// Set description of the node's first file in field field_files. | |
$wrapper->field_files[0]->description = 'The first file'; | |
$wrapper->save(); | |
// Get node object. | |
$node = $wrapper->value(); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment