You are here

function _commerce_wishlist_get_context_entity_id in Commerce Wishlist 7

Same name and namespace in other branches
  1. 7.2 commerce_wishlist.module \_commerce_wishlist_get_context_entity_id()

Helper function for getting entity ID. There has been an API change in Drupal Commerce 7.x-1.6 release. See https://drupal.org/node/1863776

Parameters

$context: The context array stored in $form_state

Return value

mixed An entity ID. NULL if couldn't figure out the entity ID.

3 calls to _commerce_wishlist_get_context_entity_id()
commerce_wishlist_add_form_submit in ./commerce_wishlist.module
Submit callback for commerce_cart_add_to_cart_form().
commerce_wishlist_add_form_validate in ./commerce_wishlist.module
Validate callback for commerce_cart_add_to_cart_form().
commerce_wishlist_form_alter in ./commerce_wishlist.module
Implements hook_form_alter().

File

./commerce_wishlist.module, line 364
Provides the wishlist for use in Drupal Commerce.

Code

function _commerce_wishlist_get_context_entity_id($context) {

  // TODO: What if it's not a node?
  if (isset($context['entity_type']) && $context['entity_type'] == 'node') {
    if (isset($context['entity'])) {
      return $context['entity']->nid;
    }
    elseif (isset($context['entity_id'])) {
      return $context['entity_id'];
    }
  }
  return NULL;
}