Last active
November 25, 2015 16:13
-
-
Save olragon/a1298d381e1710cf2346 to your computer and use it in GitHub Desktop.
Drupal's entity_metadata_wrapper examples
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
// @see https://www.drupal.org/node/2378611#comment-9360381 | |
$entity = entity_create('node', $values); | |
$wrapper = entity_metadata_wrapper('node', $entity); | |
$wrapper->field_my_term_reference->set(123); | |
$wrapper->save(); |
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
$term = new stdClass(); | |
$term->name = 'Drupal'; | |
$term->vocabulary_machine_name = 'cms'; // made wrapper happy | |
// wrap | |
$wrap = entity_metadata_wrapper('taxonomy_term', $term); | |
// made wrapper really save vid | |
$wrap->vocabulary->set('cms'); | |
// set field value | |
$wrap->field_version->set('7.16'); | |
// save | |
$term->save(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment