You are here

public function PriceModifiedDefaultFormatter::__construct in Price 8

Same name and namespace in other branches
  1. 3.x src/Plugin/Field/FieldFormatter/PriceModifiedDefaultFormatter.php \Drupal\price\Plugin\Field\FieldFormatter\PriceModifiedDefaultFormatter::__construct()
  2. 3.0.x src/Plugin/Field/FieldFormatter/PriceModifiedDefaultFormatter.php \Drupal\price\Plugin\Field\FieldFormatter\PriceModifiedDefaultFormatter::__construct()

Constructs a new PriceDefaultFormatter object.

Parameters

string $plugin_id: The plugin_id for the formatter.

mixed $plugin_definition: The plugin implementation definition.

\Drupal\Core\Field\FieldDefinitionInterface $field_definition: The definition of the field to which the formatter is associated.

array $settings: The formatter settings.

string $label: The formatter label display setting.

string $view_mode: The view mode.

array $third_party_settings: Any third party settings settings.

\Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager: The entity type manager.

\Drupal\price\NumberFormatterFactoryInterface $number_formatter_factory: The number formatter factory.

Overrides FormatterBase::__construct

File

src/Plugin/Field/FieldFormatter/PriceModifiedDefaultFormatter.php, line 72

Class

PriceModifiedDefaultFormatter
Plugin implementation of the 'price_modified' formatter.

Namespace

Drupal\price\Plugin\Field\FieldFormatter

Code

public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, $label, $view_mode, array $third_party_settings, EntityTypeManagerInterface $entity_type_manager, NumberFormatterFactoryInterface $number_formatter_factory) {
  parent::__construct($plugin_id, $plugin_definition, $field_definition, $settings, $label, $view_mode, $third_party_settings);
  $this->currencyStorage = $entity_type_manager
    ->getStorage('price_currency');
  $this->modifierStorage = $entity_type_manager
    ->getStorage('price_modifier');
  $this->numberFormatter = $number_formatter_factory
    ->createInstance();
  $this->numberFormatter
    ->setMaximumFractionDigits(6);
  if ($this
    ->getSetting('strip_trailing_zeroes')) {
    $this->numberFormatter
      ->setMinimumFractionDigits(0);
  }
  if ($this
    ->getSetting('display_currency_code')) {
    $this->numberFormatter
      ->setCurrencyDisplay(NumberFormatterInterface::CURRENCY_DISPLAY_CODE);
  }
}