You are here

function rooms_field_formatter_view in Rooms - Drupal Booking for Hotels, B&Bs and Vacation Rentals 7

Implements hook_field_formatter_view().

File

./rooms.module, line 655
Provides basic underlying functionality and configuration options used by all Rooms modules

Code

function rooms_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
  $element = array();
  switch ($display['type']) {
    case 'rooms_options_default':
      foreach ($items as $delta => $item) {
        $element[$delta] = array(
          '#markup' => "{$item['quantity']} x {$item['name']}",
        );
      }
      break;
    case 'rooms_options_price':
      if (module_exists('commerce_multicurrency')) {
        $currency_code = commerce_multicurrency_get_user_currency_code();
      }
      else {
        $currency_code = commerce_default_currency();
      }
      foreach ($items as $delta => $item) {
        $item_price = $item['value'] * 100;
        if (module_exists('commerce_multicurrency')) {
          $item_price = commerce_currency_convert($item_price, commerce_default_currency(), $currency_code);
        }
        $price = commerce_currency_format($item_price, $currency_code);
        if ($item['value'] > 0) {
          $element[$delta] = array(
            '#markup' => "{$item['quantity']} x {$item['name']} - {$price}",
          );
        }
        else {
          $element[$delta] = array(
            '#markup' => "{$item['quantity']} x {$item['name']}",
          );
        }
      }
      break;
    case 'rooms_options_admin':
      foreach ($items as $delta => $item) {
        $element[$delta] = array(
          '#markup' => "{$item['quantity']} x {$item['name']} - {$item['operation']} {$item['value']}",
        );
      }
      break;
  }
  return $element;
}