You are here

public function RestfulEntityBaseMultipleBundles::getList in RESTful 7

Overrides RestfulEntityBase::getList().

Overrides RestfulEntityBase::getList

File

plugins/restful/RestfulEntityBaseMultipleBundles.php, line 53
Contains RestfulEntityBaseMultipleBundles.

Class

RestfulEntityBaseMultipleBundles
@file Contains RestfulEntityBaseMultipleBundles.

Code

public function getList() {
  $entity_type = $this->entityType;
  $result = $this
    ->getQueryForList()
    ->execute();
  if (empty($result[$entity_type])) {
    return;
  }
  $account = $this
    ->getAccount();
  $request = $this
    ->getRequest();
  $ids = array_keys($result[$entity_type]);

  // Pre-load all entities.
  $entities = entity_load($entity_type, $ids);
  $return = array();
  $handlers = array();
  $resources_info = $this
    ->getBundles();
  foreach ($entities as $entity) {

    // Call each handler by its registered bundle.
    list($id, , $bundle) = entity_extract_ids($this
      ->getEntityType(), $entity);
    if (empty($handlers[$bundle])) {
      $version = $this
        ->getVersion();
      $handlers[$bundle] = restful_get_restful_handler($resources_info[$bundle], $version['major'], $version['minor']);
    }
    $bundle_handler = $handlers[$bundle];
    $bundle_handler
      ->setAccount($account);
    $bundle_handler
      ->setRequest($request);
    $return[] = $bundle_handler
      ->viewEntity($id);
  }
  return $return;
}