You are here

function oauth2_server_entity_load_by_properties in OAuth2 Server 7

Loads oauth2_server entities by their property values.

Modelled after Drupal 8's entity_load_by_properties(). Uses EntityFieldQuery because entity_load($entity_type, $ids, $conditions) doesn't allow a condition to be an array.

Parameters

string $entity_type: The entity type to load, e.g. node or user.

array $values: An associative array where the keys are the property names and the values are the values those properties must have.

Return value

array An array of entity objects indexed by their ids.

8 calls to oauth2_server_entity_load_by_properties()
oauth2_server_authorization_code_load in ./oauth2_server.module
Loads a single authorization code entity.
oauth2_server_authorization_code_load_multiple in ./oauth2_server.module
Loads multiple authorization code entities.
oauth2_server_client_load in ./oauth2_server.module
Loads a single client entity.
oauth2_server_client_load_multiple in ./oauth2_server.module
Loads multiple client entities.
oauth2_server_scope_load in ./oauth2_server.module
Loads a single scope entity.

... See full list

File

./oauth2_server.module, line 711
Provides OAuth2 server functionality.

Code

function oauth2_server_entity_load_by_properties($entity_type, array $values) {
  $entities = array();
  $query = new EntityFieldQuery();
  $query
    ->entityCondition('entity_type', $entity_type);
  foreach ($values as $key => $value) {
    $query
      ->propertyCondition($key, $value);
  }
  $result = $query
    ->execute();
  if ($result) {
    $entity_ids = array_keys($result[$entity_type]);
    $entities = entity_load($entity_type, $entity_ids);
  }
  return $entities;
}