You are here

function commerce_price_decimals_formatter_preprocess_views_view in Commerce Price Decimals Formatter 7

Implements hook_preprocess_views_view().

When the line item summary and order total area handlers are present on Views forms, it is natural for them to appear above the submit buttons that Views creates for the form. This hook checks for their existence in the footer area and moves them if necessary.

File

./commerce_price_decimals_formatter.module, line 367
Provides a display formatter for the price field in which you can specify the decimal places are displayed.

Code

function commerce_price_decimals_formatter_preprocess_views_view(&$vars) {
  $view = $vars['view'];

  // Determine if the line item summary or order total area handler is present
  // on the View.
  $has_handler = FALSE;
  foreach ($view->footer as $area) {
    if ($area instanceof commerce_price_decimals_formatter_handler_area_line_item_summary_decimals || $area instanceof commerce_price_decimals_formatter_handler_area_order_total_decimals) {
      $has_handler = TRUE;
    }
  }

  // If one of the handlers is present and the View in question is a form...
  if ($has_handler && views_view_has_form_elements($view)) {

    // Move the footer area into a row in the View positioned just above the
    // form's submit buttons.
    $vars['rows']['footer'] = array(
      '#type' => 'markup',
      '#markup' => $vars['footer'],
      '#weight' => 99,
    );
    $vars['footer'] = '';
  }
}