You are here

public function EntityDependencyIterator::__construct in Entity Dependency API 7

Constructor.

Parameters

array $entities: A structured array of entity ids and their entity types.

array $parent: The parent array of the current entity.

See also

entity_dependency_iterator()

File

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

Class

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

Code

public function __construct($entities, &$parent = NULL) {
  $this->entities = array();
  foreach ($entities as $entity_arr) {
    $entity_obj = entity_load($entity_arr['type'], array(
      $entity_arr['id'],
    ));
    if (empty($entity_obj)) {
      if (isset($parent)) {
        $error_msg = 'Failed to load %type ID %id, which is a dependency of %parent_type ID %parent_id.';
        $error_vars = array(
          '%type' => $entity_arr['type'],
          '%id' => $entity_arr['id'],
          '%parent_type' => $parent->current['type'],
          '%parent_id' => $parent->current['id'],
        );
      }
      else {
        $error_msg = t('Failed to load requested %type ID %id.');
        $error_vars = array(
          '%type' => $entity_arr['type'],
          '%id' => $entity_arr['id'],
        );
      }
      watchdog('Entity Dependency', $error_msg, $error_vars, WATCHDOG_WARNING);
    }
    else {
      $this->entities[] = $entity_arr;
    }
  }
  if (empty($parent)) {
    foreach ($this->entities as $key => $entity) {
      $this->causes[$entity['type']][$entity['id']] = FALSE;
    }
  }
  else {
    $this->causes =& $parent->causes;
    $this->checked =& $parent->checked;
    $this->traversed =& $parent->traversed;
  }
}