You are here

function hook_commerce_product_uri in Commerce Core 7

Lets modules specify the path information expected by a uri callback.

The Product module defines a uri callback for the product entity even though it doesn't actually define any product menu items. The callback invokes this hook and will return the first set of path information it finds. If the Product UI module is enabled, it will alter the product entity definition to use its own uri callback that checks commerce_product_uri() for a return value and defaults to an administrative link defined by that module.

This hook is used as demonstrated below by the Product Reference module to direct modules to link the product to the page where it is actually displayed to the user. Currently this is specific to nodes, but the system should be beefed up to accommodate even non-entity paths.

Parameters

$product: The product object whose uri information should be returned.

Return value

Implementations of this hook should return an array of information as expected to be returned to entity_uri() by a uri callback function.

See also

commerce_product_uri()

entity_uri()

1 function implements hook_commerce_product_uri()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

commerce_product_reference_commerce_product_uri in modules/product_reference/commerce_product_reference.module
Implements hook_commerce_product_uri().
1 invocation of hook_commerce_product_uri()
commerce_product_uri in modules/product/commerce_product.module
Entity uri callback: gives modules a chance to specify a path for a product.

File

modules/product/commerce_product.api.php, line 132
Hooks provided by the Product module.

Code

function hook_commerce_product_uri($product) {

  // If the product has a display context, use it entity_uri().
  if (!empty($product->display_context)) {
    return entity_uri($product->display_context['entity_type'], $product->display_context['entity']);
  }
}