You are here

public function Group::getEntitiesOfType in Group 7

Get all child entities of a certain type.

Parameters

string $entity_type: The type of child entities.

string $bundle: (optional) The bundle of the entity type.

Return value

array An array of child entities of a certain type and optionally bundle, keyed by their entity id.

1 call to Group::getEntitiesOfType()
Group::getSubgroups in classes/group.inc
Retrieve all subgroups for a group.

File

classes/group.inc, line 183
Defines the Entity API class for groups.

Class

Group
Main class for groups.

Code

public function getEntitiesOfType($entity_type, $bundle = NULL) {

  // We can reuse the cached result of Group::getEntities().
  $children = $this
    ->getEntities();

  // Fetch the child entities of the requested type or
  // initialize an empty array when none were found.
  $children = isset($children[$entity_type]) ? $children[$entity_type] : array();
  if (isset($bundle)) {

    // Fetch the child entities of the requested bundle or
    // initialize an empty array when none were found.
    $entities = isset($children[$bundle]) ? $children[$bundle] : array();
  }
  else {
    $combined = array();
    foreach ($children as $bundle => $entities) {
      $combined += $entities;
    }
    $entities = $combined;
  }
  return $entities;
}