You are here

class ConfigFilterServiceProvider in Config Filter 8

Service provider to swap out the config sync service.

Hierarchy

Expanded class hierarchy of ConfigFilterServiceProvider

File

src/ConfigFilterServiceProvider.php, line 15

Namespace

Drupal\config_filter
View source
class ConfigFilterServiceProvider extends ServiceProviderBase {

  /**
   * {@inheritdoc}
   */
  public function alter(ContainerBuilder $container) {
    if ($container
      ->hasDefinition('config.storage.sync')) {
      $original = $container
        ->getDefinition('config.storage.sync');
      $id = 'config.storage.sync';
    }
    elseif ($container
      ->hasDefinition('config.storage.staging')) {

      // For Drupal 8.
      $original = $container
        ->getDefinition('config.storage.staging');
      $id = 'config.storage.staging';
    }
    else {
      throw new ServiceNotFoundException('config_filter.storage.original', 'config.storage.sync');
    }

    // Save the original service so that we can use it in the factory.
    $container
      ->setDefinition('config_filter.storage.original', $original);
    $definition = new Definition(FilteredStorage::class);
    $definition
      ->setFactory([
      new Reference('config_filter.storage_factory'),
      'getSync',
    ]);
    $container
      ->setDefinition($id, $definition);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ConfigFilterServiceProvider::alter public function Modifies existing service definitions. Overrides ServiceProviderBase::alter
ServiceProviderBase::register public function Registers services to the container. Overrides ServiceProviderInterface::register 1