php - EntityMetadataWrapperException: unknown data property for field -


i have been trying update code use entity wrappers access field values. have this:

$wrapper = entity_metadata_wrapper("node", $nid); print($wrapper->field_property_sample()->value()); 

instead of this:

print($node->field_property_sample[language_none][0]["value"]); 

the problem encounter this:

entitymetadatawrapperexception: unknown data property field_property_sample.

is there way me workaround this?

i have 10 of these fields can throw exception , getting ugly

$wrapper = entity_metadata_wrapper("node", $nid);  try {   print($wrapper->field_property_sample()->value()); } catch (entitymetadatawrapperexception &e){   print(""); }  /** repeat 10 times **/ 

is there function can more or less call this?

$wrapper = entity_metadata_wrapper("node", $nid); print($wrapper->field_property_sample->exists() ? $wrapper->field_property_sample->value()  : "" );  /** repeat 10 times **/ 

yep, can use existing features of php language

try {   print($wrapper->field_property_sample->value()); } catch (entitymetadatawrapperexception $e) {   // recover } 

or, since entitymetadatawrapper implements __isset() can use that:

print isset($wrapper->field_property_sample) ? $wrapper->field_property_sample->value() : ''; 

Comments

Popular posts from this blog

java - How to Configure JAXRS and Spring With Annotations -

visual studio - TFS will not accept changes I've made to a Java project -

php - Create image in codeigniter on the fly -