Commit 709da878 authored by bojanz's avatar bojanz

Issue #3099314 by bojanz: The currency_code views filter does not provide available options

parent 4f1633fd
......@@ -68,3 +68,6 @@ field.formatter.settings.commerce_price_calculated:
sequence:
type: string
label: 'Adjustment type'
views.filter.commerce_currency:
type: views.filter.in_operator
<?php
namespace Drupal\commerce_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("commerce_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('commerce_currency');
$currencies = $currency_storage->loadMultiple();
$currency_codes = array_keys($currencies);
$this->valueOptions = array_combine($currency_codes, $currency_codes);
}
return $this->valueOptions;
}
}
......@@ -346,6 +346,9 @@ class CommerceEntityViewsData extends EntityViewsData {
if ($field_column_name == 'number') {
$views_field['filter']['id'] = 'numeric';
}
elseif ($field_column_name == 'currency_code') {
$views_field['filter']['id'] = 'commerce_currency';
}
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment