diff --git a/context_uuid_condition.inc b/context_uuid_condition.inc index 1206f33..e5d7c09 100644 --- a/context_uuid_condition.inc +++ b/context_uuid_condition.inc @@ -54,10 +54,38 @@ class context_uuid_condition extends context_condition { $values = $this->fetch_from_context($context, 'values'); foreach ($values as $item) { list($entity_type, $uuid) = explode(':', $item); - if ($entity = menu_get_object($entity_type)) { - if (!empty($entity->uuid) && $entity->uuid == $uuid) { - $this->condition_met($context); - } + + // Get information about the current path and the entity in order to + // determine whether or not we're currently on a page that displays + // entities of this type. + $active_menu_item = menu_get_item(); + $entity_info = entity_get_info($entity_type); + $entity_path = preg_replace("/(?<=\/%)$entity_type/ui", '', $entity_info['path']); + if ($entity_path != $active_menu_item['path']) { + // We're not on a page for this entity type, bail out. + return; + } + + // Get the id for this entity based on the position for the first + // argument for the current path. + $argument_position = array_search('%', explode('/', $entity_path)); + $current_entity_id = $active_menu_item['page_arguments'][$argument_position]; + + // Create and execute a query that fetches the entity id based on the + // entity type and its UUID. + $query = new EntityFieldQuery(); + $query->entityCondition('entity_type', $entity_type) + ->propertyCondition('uuid', $uuid); + $result = $query->execute(); + if (!$result[$entity_type]) { + // Didn't find any entity, bail out. + return; + } + $condition_entity_id = key($result[$entity_type]); + + // Check if the current entity is the one specified for the condition. + if ($current_entity_id == $condition_entity_id) { + $this->condition_met($context); } } }