You are here

function uuid_entity_uuid_context in Universally Unique IDentifier 7

Discover if this argument gives us the entity we crave.

1 string reference to 'uuid_entity_uuid_context'
entity_uuid.inc in plugins/arguments/entity_uuid.inc
Plugin to provide an argument handler for all entity IDs.

File

plugins/arguments/entity_uuid.inc, line 60
Plugin to provide an argument handler for all entity IDs.

Code

function uuid_entity_uuid_context($arg = NULL, $conf = NULL, $empty = FALSE) {
  $entity_type = explode(':', $conf['name']);
  $entity_type = $entity_type[1];

  // If unset it wants a generic, unfilled context.
  if ($empty) {
    return ctools_context_create_empty('entity:' . $entity_type);
  }

  // We can accept either an entity object or a pure id.
  if (is_object($arg)) {
    return ctools_context_create('entity:' . $entity_type, $arg);
  }
  if (!is_string($arg)) {
    return FALSE;
  }
  $entity_ids = entity_get_id_by_uuid($entity_type, array(
    $arg,
  ));
  if (!isset($entity_ids[$arg])) {
    return FALSE;
  }
  $entity_id = $entity_ids[$arg];
  $entities = entity_load($entity_type, array(
    $entity_id,
  ));
  if (!$entities) {
    return FALSE;
  }
  return ctools_context_create('entity:' . $entity_type, $entities[$entity_id]);
}