You are here

Currency.php in Price 2.x

Same filename in this branch
  1. 2.x src/Entity/Currency.php
  2. 2.x src/Plugin/views/filter/Currency.php
Same filename and directory in other branches
  1. 2.0.x src/Plugin/views/filter/Currency.php

File

src/Plugin/views/filter/Currency.php
View source
<?php

namespace Drupal\price\Plugin\views\filter;

use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\views\Plugin\views\filter\InOperator;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
 * Filter by currency.
 *
 * @ViewsFilter("price_currency")
 */
class Currency extends InOperator {

  /**
   * The entity type manager.
   *
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   */
  protected $entityTypeManager;

  /**
   * Constructs a new Currency object.
   *
   * @param array $configuration
   *   A configuration array containing information about the plugin instance.
   * @param string $plugin_id
   *   The plugin_id for the plugin instance.
   * @param mixed $plugin_definition
   *   The plugin implementation definition.
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   The entity type manager.
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $this->entityTypeManager = $entity_type_manager;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    return new static($configuration, $plugin_id, $plugin_definition, $container
      ->get('entity_type.manager'));
  }

  /**
   * {@inheritdoc}
   */
  public function getValueOptions() {
    if (!isset($this->valueOptions)) {
      $currency_storage = $this->entityTypeManager
        ->getStorage('price_currency');
      $currencies = $currency_storage
        ->loadMultiple();
      $currency_codes = array_keys($currencies);
      $this->valueOptions = array_combine($currency_codes, $currency_codes);
    }
    return $this->valueOptions;
  }

}

Classes

Namesort descending Description
Currency Filter by currency.