You are here

protected function PriceTableDefaultFormatter::getQuantityHeaders in Commerce Price Table 8

Helper method that takes care of the quantity displayed in the headers of the price table.

1 call to PriceTableDefaultFormatter::getQuantityHeaders()
PriceTableDefaultFormatter::viewElements in src/Plugin/Field/FieldFormatter/PriceTableDefaultFormatter.php
Builds a renderable array for a field value.

File

src/Plugin/Field/FieldFormatter/PriceTableDefaultFormatter.php, line 180

Class

PriceTableDefaultFormatter
Plugin implementation of the 'commerce_price_table' formatter.

Namespace

Drupal\commerce_price_table\Plugin\Field\FieldFormatter

Code

protected function getQuantityHeaders($item) {

  // Set the quantity text to unlimited if it's -1. $item->min_qty
  $max_qty = $item->max_qty == -1 ? $this
    ->t('Unlimited') : $item->max_qty;

  // If max and min qtys are the same, only show one.
  if ($item->min_qty == $max_qty) {
    $quantity_text = $item->min_qty;
  }
  else {
    $quantity_text = $item->min_qty . ' - ' . $max_qty;
  }
  return $quantity_text;
}