You are here

function basic_cart_field_formatter_view in Basic cart 7.3

Implements hook_field_formatter_view().

File

./basic_cart.module, line 296

Code

function basic_cart_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
  $element = array();
  $settings = $display['settings'];
  switch ($display['type']) {
    case 'basic_cart_add_to_cart':
      if (!empty($items) && is_array($items)) {
        foreach ($items as $delta => $item) {
          $css_class = !empty($settings['css_class']) ? $settings['css_class'] : '';
          $element[$delta] = array(
            '#markup' => theme('basic_cart_add_to_cart', array(
              'path' => 'cart/add/' . $entity->nid,
              'css_class' => $css_class,
            )),
          );
        }
      }
      else {
        $css_class = !empty($settings['css_class']) ? $settings['css_class'] : '';
        $element[] = array(
          '#markup' => theme('basic_cart_add_to_cart', array(
            'path' => 'cart/add/' . $entity->nid,
            'css_class' => $css_class,
          )),
        );
      }
      break;
    case 'basic_cart_add_to_cart_quantity':
      $element[] = drupal_get_form('basic_cart_add_to_cart_quantity_form', $entity->nid);
      break;
    case 'basic_cart_price':
      foreach ($items as $delta => $item) {
        $value = basic_cart_price_format($item['value']);
        $element[$delta] = array(
          '#markup' => theme('basic_cart_price', array(
            'price' => $value,
          )),
        );
      }
      break;
  }
  return $element;
}