You are here

class SyncFilterDeriver in Configuration Synchronizer 8.2

Deriver for SyncFilter filters.

Hierarchy

Expanded class hierarchy of SyncFilterDeriver

File

src/Plugin/ConfigFilter/SyncFilterDeriver.php, line 18

Namespace

Drupal\config_sync\Plugin\ConfigFilter
View source
class SyncFilterDeriver extends DeriverBase implements ContainerDeriverInterface {
  use StringTranslationTrait;

  /**
   * The configuration synchronizer lister.
   *
   * @var \Drupal\config_sync\configSyncListerInterface
   */
  protected $configSyncLister;

  /**
   * The module handler.
   *
   * @var \Drupal\Core\Extension\ModuleHandlerInterface
   */
  protected $moduleHandler;

  /**
   * The theme handler.
   *
   * @var \Drupal\Core\Extension\ThemeHandlerInterface
   */
  protected $themeHandler;

  /**
   * The state storage object.
   *
   * @var \Drupal\Core\State\StateInterface
   */
  protected $state;

  /**
   * SyncFilter constructor.
   *
   * @param \Drupal\config_sync\ConfigSyncListerInterface $config_sync_lister
   *   The configuration synchronizer lister.
   * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
   *   The module handler.
   * @param \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler
   *   The theme handler.
   * @param \Drupal\Core\State\StateInterface $state
   *   The state storage object.
   */
  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;
  }

  /**
   * {@inheritdoc}
   */
  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'));
  }

  /**
   * {@inheritdoc}
   */
  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,
        ]);

        // Status can be overridden in the state.
        $this->derivatives[$key]['status'] = !isset($plugin_data[$type][$name]['status']) || $plugin_data[$type][$name]['status'] === TRUE;
      }
    }
    return $this->derivatives;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DeriverBase::$derivatives protected property List of derivative definitions. 1
DeriverBase::getDerivativeDefinition public function Gets the definition of a derivative plugin. Overrides DeriverInterface::getDerivativeDefinition
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.
SyncFilterDeriver::$configSyncLister protected property The configuration synchronizer lister.
SyncFilterDeriver::$moduleHandler protected property The module handler.
SyncFilterDeriver::$state protected property The state storage object.
SyncFilterDeriver::$themeHandler protected property The theme handler.
SyncFilterDeriver::create public static function Creates a new class instance. Overrides ContainerDeriverInterface::create
SyncFilterDeriver::getDerivativeDefinitions public function Gets the definition of all derivatives of a base plugin. Overrides DeriverBase::getDerivativeDefinitions
SyncFilterDeriver::__construct public function SyncFilter constructor.