You are here

commerce_price_table_ief.module in Commerce Price Table 7

File

commerce_price_table_ief/commerce_price_table_ief.module
View source
<?php

/**
 * Implements hook_entity_info_alter().
 */
function commerce_price_table_ief_entity_info_alter(&$entity_info) {

  // We'll use our custom contoller.
  if (isset($entity_info['commerce_product'])) {
    $entity_info['commerce_product']['inline entity form'] = array(
      'controller' => 'PriceTableCommerceProductInlineEntityFormController',
    );

    // We'll define a custom view mode for this entity.
    $entity_info['commerce_product']['view modes']['inline_entity_form'] = array(
      'label' => t('Inline Entity Form'),
      'custom settings' => TRUE,
    );
  }
}

/**
 * Implements hook_field_formatter_info().
 */
function commerce_price_table_ief_field_formatter_info() {
  return array(
    'commerce_multiprice_list_ief' => array(
      'label' => t('Price list (for inline entity form)'),
      'field types' => array(
        'commerce_price_table',
      ),
      'settings' => array(
        'calculation' => FALSE,
      ),
    ),
  );
}

/**
 * Implements hook_field_formatter_view().
 */
function commerce_price_table_ief_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
  $element = array();
  if ($display['type'] == 'commerce_multiprice_list_ief' && !empty($items)) {
    uasort($items, 'commerce_price_table_sort_by_qty');
    $list_items = array();
    foreach ($items as $delta => $item) {
      if (isset($item['min_qty']) && $item['amount']) {
        $header = commerce_price_table_display_quantity_headers($item);
        $price = commerce_currency_format($item['amount'], $item['currency_code'], $entity);
        $list_items[] = "{$price} ({$header})";
      }
    }
    $element[] = array(
      '#markup' => theme('item_list', array(
        'items' => $list_items,
      )),
    );
  }
  return $element;
}

/**
 * Implements hook_inline_entity_form_entity_form_alter().
 */
function commerce_price_table_ief_inline_entity_form_entity_form_alter(&$entity_form, $form_state) {
  commerce_price_table_form_commerce_product_ui_product_form_alter($entity_form, $form_state, 'commerce_product_ui_product_form');
}