You are here

public function EntityDependencyIterator::current in Entity Dependency API 7

Get the current entity formatted with some extra metadata according to the OData protocol.

See also

http://www.odata.org/developers/protocols

File

./EntityDependencyIterator.inc, line 228
Entity Dependency classes.

Class

EntityDependencyIterator
Iterator class which does the heavy lifting for detecting dependencies.

Code

public function current() {
  $current = current($this->entities);

  // Load the current entity.
  $entities = entity_load($current['type'], array(
    $current['id'],
  ));
  $entity = reset($entities);

  // Add necessary metadata to the entity.
  $cause = FALSE;
  if (!empty($this->causes[$current['type']][$current['id']])) {
    $cause = $this->causes[$current['type']][$current['id']]['type'] . '/' . $this->causes[$current['type']][$current['id']]['id'];
  }
  $entity->__metadata = array(
    'type' => $current['type'],
    'uri' => $current['type'] . '/' . $current['id'],
    'cause' => $cause,
  );

  // Now mark this as traversed.
  $this->traversed[$current['type']][$current['id']] = TRUE;
  return $entity;
}