You are here

function commerce_pricelist_item_view in Commerce Pricelist 7

Menu callback to display an entity.

As we load the entity for display, we're responsible for invoking a number of hooks in their proper order.

See also

hook_entity_prepare_view()

hook_entity_view()

hook_entity_view_alter()

File

includes/commerce_pricelist.admin.inc, line 512
Summary

Code

function commerce_pricelist_item_view($entity, $view_mode = 'full') {

  // Our entity type, for convenience.
  $entity_type = 'commerce_pricelist_item';

  // Start setting up the content.
  $entity->content = array(
    '#view_mode' => $view_mode,
  );

  // We call entity_prepare_view() so it can invoke hook_entity_prepare_view()
  // for us.
  entity_prepare_view($entity_type, array(
    $entity->item_id => $entity,
  ));

  // OK, Field API done, now we can set up some of our own data.
  $entity->content['pricelist_id'] = array(
    '#type' => 'item',
    '#title' => t('Price list ID'),
    '#markup' => $entity->pricelist_id,
  );

  // Now to invoke some hooks. We need the language code for
  // hook_entity_view(), so let's get that.
  global $language;
  $langcode = $language->language;

  // And now invoke hook_entity_view().
  module_invoke_all('entity_view', $entity, $entity_type, $view_mode, $langcode);

  // Now invoke hook_entity_view_alter().
  drupal_alter(array(
    'commerce_pricelist_item_view',
    'entity_view',
  ), $entity->content, $entity_type);

  // And finally return the content.
  return $entity->content;
}