You are here

protected function EntityDrupalWrapper::spotBundleInfo in Entity API 7

Tries to determine the bundle and adds in the according property info.

Parameters

$load: Whether the entity should be loaded to spot the info if necessary.

2 calls to EntityDrupalWrapper::spotBundleInfo()
EntityDrupalWrapper::setUp in includes/entity.wrapper.inc
EntityDrupalWrapper::spotInfo in includes/entity.wrapper.inc
Used to lazy-load bundle info. So the wrapper can be loaded e.g. just for setting without the data being loaded.

File

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

Class

EntityDrupalWrapper
Provides a wrapper for entities registrered in hook_entity_info().

Code

protected function spotBundleInfo($load = TRUE) {

  // Like entity_extract_ids() assume the entity type if no key is given.
  if (empty($this->entityInfo['entity keys']['bundle']) && $this->type != 'entity') {
    $this->bundle = $this->type;
  }
  elseif (!$this->bundle && $load && $this
    ->dataAvailable()) {
    try {
      if ($entity = $this
        ->value()) {
        list($id, $vid, $bundle) = entity_extract_ids($this->type, $entity);
        $this->bundle = $bundle;
      }
    } catch (EntityMetadataWrapperException $e) {

      // Loading data failed, so we cannot derive the used bundle.
    }
  }
  if ($this->bundle && isset($this->propertyInfo['bundles'][$this->bundle])) {
    $bundle_info = (array) $this->propertyInfo['bundles'][$this->bundle] + array(
      'properties' => array(),
    );

    // Allow bundles to re-define existing properties, such that the bundle
    // can add in more bundle-specific details like the bundle of a referenced
    // entity.
    $this->propertyInfo['properties'] = $bundle_info['properties'] + $this->propertyInfo['properties'];
  }
}