SyncFilterDeriver.php in Configuration Synchronizer 8.2
File
src/Plugin/ConfigFilter/SyncFilterDeriver.php
View source
<?php
namespace Drupal\config_sync\Plugin\ConfigFilter;
use Drupal\config_sync\ConfigSyncListerInterface;
use Drupal\Component\Plugin\Derivative\DeriverBase;
use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Extension\ThemeHandlerInterface;
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
use Drupal\Core\State\StateInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Symfony\Component\DependencyInjection\ContainerInterface;
class SyncFilterDeriver extends DeriverBase implements ContainerDeriverInterface {
use StringTranslationTrait;
protected $configSyncLister;
protected $moduleHandler;
protected $themeHandler;
protected $state;
public function __construct(ConfigSyncListerInterface $config_sync_lister, ModuleHandlerInterface $module_handler, ThemeHandlerInterface $theme_handler, StateInterface $state) {
$this->configSyncLister = $config_sync_lister;
$this->moduleHandler = $module_handler;
$this->themeHandler = $theme_handler;
$this->state = $state;
}
public static function create(ContainerInterface $container, $base_plugin_id) {
return new static($container
->get('config_sync.lister'), $container
->get('module_handler'), $container
->get('theme_handler'), $container
->get('state'));
}
public function getDerivativeDefinitions($base_plugin_definition) {
$plugin_data = $this->state
->get('config_sync.plugins', []);
$type_labels = [
'module' => $this
->t('Module'),
'theme' => $this
->t('Theme'),
];
foreach ($this->configSyncLister
->getExtensionChangelists() as $type => $extension_changelists) {
foreach (array_keys($extension_changelists) as $name) {
$key = $type . '_' . $name;
$this->derivatives[$key] = $base_plugin_definition;
$this->derivatives[$key]['extension_type'] = $type;
$this->derivatives[$key]['extension_name'] = $name;
switch ($type) {
case 'module':
$label = $this->moduleHandler
->getName($name);
$type_label = $this
->t('Module');
break;
case 'theme':
$label = $this->themeHandler
->getName($name);
$type_label = $this
->t('Theme');
break;
}
$this->derivatives[$key]['label'] = $this
->t('@type_label: @label', [
'@type_label' => $type_label,
'@label' => $label,
]);
$this->derivatives[$key]['status'] = !isset($plugin_data[$type][$name]['status']) || $plugin_data[$type][$name]['status'] === TRUE;
}
}
return $this->derivatives;
}
}