You are here

UcPriceFormatter.php in Ubercart 8.4

File

uc_product/src/Plugin/Field/FieldFormatter/UcPriceFormatter.php
View source
<?php

namespace Drupal\uc_product\Plugin\Field\FieldFormatter;

use Drupal\Core\Field\FormatterBase;
use Drupal\Core\Field\FieldItemListInterface;

/**
 * Plugin implementation of the Ubercart price formatter.
 *
 * @FieldFormatter(
 *   id = "uc_price",
 *   label = @Translation("Price"),
 *   field_types = {
 *     "uc_price",
 *   }
 * )
 */
class UcPriceFormatter extends FormatterBase {

  /**
   * {@inheritdoc}
   */
  public function viewElements(FieldItemListInterface $items, $langcode) {
    $elements = [];
    foreach ($items as $delta => $item) {
      $elements[$delta] = [
        '#markup' => uc_currency_format($item->value),
      ];
    }
    return $elements;
  }

}

Classes

Namesort descending Description
UcPriceFormatter Plugin implementation of the Ubercart price formatter.