Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function present($value, array $options = [])
 {
     if (isset($options['versioned_attribute'])) {
         $value = $this->getStructuredMetric($value, $options['versioned_attribute']);
     }
     $amount = isset($value['data']) ? parent::present($value['data'], $options) : null;
     $unit = isset($value['unit']) ? $this->translatorProxy->trans($value['unit'], ['domain' => 'measures']) : null;
     return trim(sprintf('%s %s', $amount, $unit));
 }
Exemplo n.º 2
0
 /**
  * {@inheritdoc}
  *
  * Presents a structured price set to be readable. If locale option is set, the prices are formatted according to
  * the locale. If no locale option is set, the default is the price amount then the currency symbol.
  */
 public function present($prices, array $options = [])
 {
     if ('' === $prices || null === $prices) {
         return $prices;
     }
     if (!is_array($prices)) {
         if (!isset($options['versioned_attribute'])) {
             return parent::present($prices, $options);
         }
         $prices = $this->getStructuredPrice($prices, $options['versioned_attribute']);
     }
     $numberFormatter = $this->numberFactory->create(array_merge($options, ['type' => \NumberFormatter::CURRENCY]));
     if (array_key_exists('data', $prices) && array_key_exists('currency', $prices)) {
         return $this->getPrice($numberFormatter, $prices);
     }
     $presentedPrices = [];
     foreach ($prices as $price) {
         if ('' !== ($presentedPrice = $this->getPrice($numberFormatter, $price))) {
             $presentedPrices[] = $presentedPrice;
         }
     }
     return implode(', ', $presentedPrices);
 }