WebformVariantManager.php in Webform 8.5
File
src/Plugin/WebformVariantManager.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 WebformVariantManager extends DefaultPluginManager implements WebformVariantManagerInterface {
use CategorizingPluginManagerTrait {
getSortedDefinitions as traitGetSortedDefinitions;
getGroupedDefinitions as traitGetGroupedDefinitions;
}
protected $configFactory;
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler, ConfigFactoryInterface $config_factory) {
parent::__construct('Plugin/WebformVariant', $namespaces, $module_handler, 'Drupal\\webform\\Plugin\\WebformVariantInterface', 'Drupal\\webform\\Annotation\\WebformVariant');
$this->configFactory = $config_factory;
$this
->alterInfo('webform_variant_info');
$this
->setCacheBackend($cache_backend, 'webform_variant_plugins');
}
public function getSortedDefinitions(array $definitions = NULL, $sort_by = 'label') {
$definitions = $this
->traitGetSortedDefinitions($definitions, $sort_by);
return $definitions;
}
public function getGroupedDefinitions(array $definitions = NULL) {
$definitions = $this
->traitGetGroupedDefinitions($definitions);
unset($definitions[$this
->t('Broken')]['broken']);
return $definitions;
}
public function removeExcludeDefinitions(array $definitions) {
$definitions = isset($definitions) ? $definitions : $this
->getDefinitions();
unset($definitions['broken']);
$excluded = $this->configFactory
->get('webform.settings')
->get('variant.excluded_variants') ?: [];
return $excluded ? array_diff_key($definitions, $excluded) : $definitions;
}
public function getFallbackPluginId($plugin_id, array $configuration = []) {
return 'broken';
}
}