WebformExporterManager.php in Webform 6.x
File
src/Plugin/WebformExporterManager.php
View source
<?php
namespace Drupal\webform\Plugin;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Plugin\CategorizingPluginManagerTrait;
use Drupal\Core\Plugin\DefaultPluginManager;
class WebformExporterManager extends DefaultPluginManager implements WebformExporterManagerInterface {
use CategorizingPluginManagerTrait {
getSortedDefinitions as traitGetSortedDefinitions;
}
protected $configFactory;
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_exporter, ConfigFactoryInterface $config_factory) {
parent::__construct('Plugin/WebformExporter', $namespaces, $module_exporter, 'Drupal\\webform\\Plugin\\WebformExporterInterface', 'Drupal\\webform\\Annotation\\WebformExporter');
$this->configFactory = $config_factory;
$this
->alterInfo('webform_exporter_info');
$this
->setCacheBackend($cache_backend, 'webform_exporter_plugins');
}
public function getSortedDefinitions(array $definitions = NULL, $sort_by = 'label') {
$definitions = $this
->traitGetSortedDefinitions($definitions, $sort_by);
return $definitions;
}
public function removeExcludeDefinitions(array $definitions) {
$definitions = isset($definitions) ? $definitions : $this
->getDefinitions();
$excluded = $this->configFactory
->get('webform.settings')
->get('export.excluded_exporters');
return $excluded ? array_diff_key($definitions, $excluded) : $definitions;
}
public function getInstances(array $configuration = []) {
$instances = [];
$plugin_definitions = $this
->getDefinitions();
$plugin_definitions = $this
->getSortedDefinitions($plugin_definitions);
$plugin_definitions = $this
->removeExcludeDefinitions($plugin_definitions);
foreach ($plugin_definitions as $plugin_id => $plugin_definition) {
$instances[$plugin_id] = $this
->createInstance($plugin_id, $configuration);
}
return $instances;
}
public function getOptions() {
$plugin_definitions = $this
->getDefinitions();
$plugin_definitions = $this
->getSortedDefinitions($plugin_definitions);
$plugin_definitions = $this
->removeExcludeDefinitions($plugin_definitions);
$options = [];
foreach ($plugin_definitions as $plugin_id => $plugin_definition) {
$options[$plugin_id] = $plugin_definition['label'];
}
return $options;
}
public function getFallbackPluginId($plugin_id, array $configuration = []) {
return 'delimited';
}
}