You are here

public function EntityMetadataWrapper::validate in Entity API 7

Returns whether $value is a valid value to set.

3 calls to EntityMetadataWrapper::validate()
EntityDrupalWrapper::set in includes/entity.wrapper.inc
Overridden to support setting the entity by either the object or the id.
EntityListWrapper::validate in includes/entity.wrapper.inc
Overridden.
EntityMetadataWrapper::set in includes/entity.wrapper.inc
Set a new data value.
1 method overrides EntityMetadataWrapper::validate()
EntityListWrapper::validate in includes/entity.wrapper.inc
Overridden.

File

includes/entity.wrapper.inc, line 146
Provides wrappers allowing easy usage of the entity metadata.

Class

EntityMetadataWrapper
A common base class for all wrappers.

Code

public function validate($value) {
  if (isset($value) && !entity_property_verify_data_type($value, $this->type)) {
    return FALSE;
  }

  // Only proceed with further checks if this is not a list item. If this is
  // a list item, the checks are performed on the list property level.
  if (isset($this->info['parent']) && $this->info['parent'] instanceof EntityListWrapper) {
    return TRUE;
  }
  if (!isset($value) && !empty($this->info['required'])) {

    // Do not allow NULL values if the property is required.
    return FALSE;
  }
  return !isset($this->info['validation callback']) || call_user_func($this->info['validation callback'], $value, $this->info);
}