You are here

function commerce_registration_entity_view_alter in Commerce Registration 7.2

Implements hook_entity_view_alter().

File

./commerce_registration.module, line 745
Commerce Registration module code.

Code

function commerce_registration_entity_view_alter(&$build, $type) {
  if ($type == "commerce_order") {

    // If we're viewing an order, add registrations to the order if available.
    $regs = db_select('registration', 'r')
      ->fields('r', array(
      'registration_id',
    ))
      ->condition('order_id', (int) $build['#entity']->order_id)
      ->execute();
    $build['commerce_registration'] = array(
      '#title' => t('Registrations'),
    );
    $variables['registrations'] = array();
    foreach ($regs as $row) {
      $variables['registrations'][] = registration_load($row->registration_id);
    }
    if (!empty($variables['registrations'])) {
      $build['commerce_registration'][0]['#markup'] = theme('commerce_registration_order', $variables);
    }
  }
  else {
    if ($type == "registration") {

      // Add the Commerce Order to the registration view.
      $vars = array(
        '!num' => $build['#entity']->order_id,
      );
      $build['commerce_registration_order'][0]['#markup'] = l(t('Order !num', $vars), 'admin/commerce/orders/' . $build['#entity']->order_id);
    }
  }
}