You are here

function uc_length_format in Ubercart 7.3

Same name and namespace in other branches
  1. 8.4 uc_store/uc_store.module \uc_length_format()
  2. 5 uc_store/uc_store.module \uc_length_format()
  3. 6.2 uc_store/uc_store.module \uc_length_format()

Formats a length value for display.

Parameters

$value: Numerical length value.

$unit: Length unit. One of 'ft', 'in', 'cm', or 'mm', or NULL to use store default length units.

Return value

String containing formattted length, including length units.

4 calls to uc_length_format()
theme_uc_product_dimensions in uc_product/uc_product.theme.inc
Formats a product's length, width, and height.
uc_product_handler_field_length::render in uc_product/views/uc_product_handler_field_length.inc
Overrides views_handler_field::render().
uc_product_tokens in uc_product/uc_product.tokens.inc
Implements hook_tokens().
uc_shipping_package_view in shipping/uc_shipping/uc_shipping.module
Displays the details of a package.

File

uc_store/uc_store.module, line 1034
Contains global Ubercart functions and store administration functionality.

Code

function uc_length_format($value, $unit = NULL) {
  $vars = array(
    '!value' => $value,
  );
  if (is_null($unit)) {
    $unit = variable_get('uc_length_unit', 'in');
  }
  $defaults = array(
    'in' => '!valuein.',
    'ft' => '!valueft.',
    'cm' => '!valuecm',
    'mm' => '!valuemm',
  );
  $pattern = variable_get('uc_length_format_' . $unit, $defaults[$unit]);
  if (strpos($pattern, '!value') === FALSE) {
    $pattern = $defaults[$unit];
  }
  $format = strtr($pattern, $vars);
  return $format;
}