You are here

function entity_dependency_add in Entity Dependency API 7

Helper function to add entity dependencies to a dependency array.

We never treat user UID 0 or 1 as dependencies. Those are low level user accounts ("anonymous" and "root") that already exists in most systems.

Parameters

$dependencies: The dependency array.

$objects: Array of objects that should be checked for dependencies in $properties.

$entity_type: The type of entity that $properties will add dependency on.

$properties: An array of properties that adds dependencies to $objects. All properties must only point to one entity type at the time.

See also

entity_dependency.core.inc

11 calls to entity_dependency_add()
comment_entity_dependencies in ./entity_dependency.core.inc
Implements hook_entity_dependenies().
entityreference_field_entity_dependencies in ./entity_dependency.core.inc
Implements hook_field_entity_dependencies().
field_collection_field_entity_dependencies in ./entity_dependency.core.inc
Implements hook_field_entity_dependencies().
file_entity_dependencies in ./entity_dependency.core.inc
Implements hook_entity_dependenies().
file_field_entity_dependencies in ./entity_dependency.core.inc
Implements hook_field_entity_dependencies().

... See full list

File

./entity_dependency.module, line 54
Entity Depedendency module functions.

Code

function entity_dependency_add(&$dependencies, $objects, $entity_type, $properties) {
  if (!is_array($objects)) {
    $objects = array(
      $objects,
    );
  }
  if (!is_array($properties)) {
    $properties = array(
      $properties,
    );
  }
  foreach ($objects as $object) {
    foreach ($properties as $property) {
      $value = NULL;
      if (is_object($object) && isset($object->{$property})) {
        $value = $object->{$property};
      }
      elseif (is_array($object) && isset($object[$property])) {
        $value = $object[$property];
      }
      if (!empty($value) && !($entity_type == 'user' && ((int) $value == 0 || (int) $value == 1))) {
        $dependencies[] = array(
          'type' => $entity_type,
          'id' => $value,
        );
      }
    }
  }
}