AmountFormatterManager.php in Currency 8.3
File
src/Plugin/Currency/AmountFormatter/AmountFormatterManager.php
View source
<?php
namespace Drupal\currency\Plugin\Currency\AmountFormatter;
use Drupal\Component\Plugin\FallbackPluginManagerInterface;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Plugin\DefaultPluginManager;
use Drupal\currency\Annotation\CurrencyAmountFormatter;
class AmountFormatterManager extends DefaultPluginManager implements AmountFormatterManagerInterface, FallbackPluginManagerInterface {
protected $configFactory;
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler, ConfigFactoryInterface $config_factory) {
parent::__construct('Plugin/Currency/AmountFormatter', $namespaces, $module_handler, AmountFormatterInterface::class, CurrencyAmountFormatter::class);
$this
->alterInfo('currency_amount_formatter');
$this
->setCacheBackend($cache_backend, 'currency_amount_formatter');
$this->configFactory = $config_factory;
}
public function getFallbackPluginId($plugin_id, array $configuration = array()) {
return 'currency_basic';
}
public function getDefaultPluginId() {
return $this->configFactory
->get('currency.amount_formatting')
->get('plugin_id');
}
public function setDefaultPluginId($plugin_id) {
$this->configFactory
->get('currency.amount_formatting')
->set('plugin_id', $plugin_id)
->save();
return $this;
}
public function getDefaultPlugin() {
return $this
->createInstance($this
->getDefaultPluginId());
}
}