diff --git a/includes/entity.wrapper.inc b/includes/entity.wrapper.inc index d5d22ac..692a5b5 100644 --- a/includes/entity.wrapper.inc +++ b/includes/entity.wrapper.inc @@ -115,6 +115,26 @@ abstract class EntityMetadataWrapper { } /** + * Returns whether data is available to work with. + * + * Exposes the EntityMetadataWrapper::dataAvailable() method result. + * + * @return + * If we operate without any data TRUE, else FALSE. + * + * @see EntityMetadataWrapper::dataAvailable() + */ + public function isEmpty() { + try { + $value = $this->value(); + } + catch (EntityMetadataWrapperException $e) { + $value = FALSE; + } + return empty($value); + } + + /** * Set a new data value. */ public function set($value) { @@ -406,6 +426,24 @@ class EntityStructureWrapper extends EntityMetadataWrapper implements IteratorAg } /** + * Safely checks if the given child exists. + * + * @param $name + * The name of the child to check. + * @return bool + * TRUE if the child exists, FALSE if it does not. + */ + public function hasChild($name) { + try { + $this->get($name); + return TRUE; + } + catch (EntityMetadataWrapperException $e) { + return FALSE; + } + } + + /** * Magic method: Get a wrapper for a property. */ public function __get($name) {