You are here

function commerce_price_field_formatter_settings_form in Commerce Core 7

Implements hook_field_formatter_settings_form().

File

modules/price/commerce_price.module, line 356
Defines the Price field with widgets and formatters used to add prices with currency codes to various Commerce entities.

Code

function commerce_price_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) {
  $display = $instance['display'][$view_mode];
  $settings = $display['settings'];
  $element = array();

  // Do not display any settings for the component formatter.
  if ($display['type'] == 'commerce_price_formatted_components') {
    return;
  }

  // Get all the price calculation options.
  $options = module_invoke_all('commerce_price_field_calculation_options', $field, $instance, $view_mode);
  if (empty($options)) {
    $element['calculation'] = array(
      '#type' => 'value',
      '#value' => FALSE,
    );
    $element['help'] = array(
      '#markup' => '<p>' . t('No configuration is necessary. The original price will be displayed as loaded.') . '</p>',
    );
  }
  else {

    // Add the option to display the original price; unshifting will give it a
    // key of 0 which will equate to FALSE with an Equal operator.
    array_unshift($options, t('Display the original price as loaded.'));
    $element['calculation'] = array(
      '#type' => 'radios',
      '#options' => $options,
      '#default_value' => empty($settings['calculation']) ? '0' : $settings['calculation'],
    );
  }
  return $element;
}