Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save aczietlow/23a9472a3322bf25f493d41ae5153d18 to your computer and use it in GitHub Desktop.
Save aczietlow/23a9472a3322bf25f493d41ae5153d18 to your computer and use it in GitHub Desktop.
diff --git a/config_ignore_drush/composer.json b/config_ignore_drush/composer.json
new file mode 100644
index 0000000..70e4fcd
--- /dev/null
+++ b/config_ignore_drush/composer.json
@@ -0,0 +1,15 @@
+{
+ "name": "drupal/config_ignore_drush",
+ "type": "drupal-drush",
+ "description": "Command replacement for config:import and config:export that applies sync and active storage filters rather than just sync.",
+ "require": {
+ "drupal/config_ignore": "^1.0"
+ },
+ "extra": {
+ "drush": {
+ "services": {
+ "drush.services.yml": "^9"
+ }
+ }
+ }
+}
diff --git a/config_ignore_drush/config_ignore_drush.info.yml b/config_ignore_drush/config_ignore_drush.info.yml
new file mode 100644
index 0000000..3157c11
--- /dev/null
+++ b/config_ignore_drush/config_ignore_drush.info.yml
@@ -0,0 +1,8 @@
+name: 'Config Ignore Drush Commands'
+type: module
+description: 'Command replacement for config:import and config:export that applies sync and active storage filters rather than just sync.'
+core: 8.x
+core_version_requirement: ^8 || ^9
+package: 'Config'
+dependencies:
+ - config_ignore
diff --git a/config_ignore_drush/drush.services.yml b/config_ignore_drush/drush.services.yml
new file mode 100644
index 0000000..b191397
--- /dev/null
+++ b/config_ignore_drush/drush.services.yml
@@ -0,0 +1,24 @@
+services:
+ config_ignore.export.commands:
+ class: \Drupal\config_ignore_drush\Commands\ConfigIgnoreExportCommands
+ arguments: ['@config.manager', '@config.storage', '@config.storage.sync', '@config_filter.storage_factory']
+ tags:
+ - { name: drush.command }
+ config_ignore.import.commands:
+ class: \Drupal\config_ignore_drush\Commands\ConfigIgnoreImportCommands
+ arguments:
+ - '@config.manager'
+ - '@config.storage'
+ - '@config.storage.sync'
+ - '@cache.config'
+ - '@module_handler'
+ - '@event_dispatcher'
+ - '@lock'
+ - '@config.typed'
+ - '@module_installer'
+ - '@theme_handler'
+ - '@string_translation'
+ - '@extension.list.module'
+ - '@config_filter.storage_factory'
+ tags:
+ - { name: drush.command }
diff --git a/config_ignore_drush/src/Commands/ConfigIgnoreExportCommands.php b/config_ignore_drush/src/Commands/ConfigIgnoreExportCommands.php
new file mode 100644
index 0000000..6800c29
--- /dev/null
+++ b/config_ignore_drush/src/Commands/ConfigIgnoreExportCommands.php
@@ -0,0 +1,42 @@
+<?php
+
+namespace Drupal\config_ignore_drush\Commands;
+
+use Drupal\config_filter\ConfigFilterStorageFactory;
+use Drush\Drupal\Commands\config\ConfigExportCommands;
+
+/**
+ * Replace config:export Drush command.
+ */
+class ConfigIgnoreExportCommands extends ConfigExportCommands {
+
+ /**
+ * @var ConfigFilterStorageFactory
+ */
+ protected $filterFactory;
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getConfigStorageExport() {
+ return $this->filterFactory->getFilteredStorage(parent::getConfigStorageExport(), ['config.storage.active']);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function __construct(\Drupal\Core\Config\ConfigManagerInterface $configManager, \Drupal\Core\Config\StorageInterface $configStorage, \Drupal\Core\Config\StorageInterface $configStorageSync, ConfigFilterStorageFactory $filter_factory) {
+ parent::__construct($configManager, $configStorage, $configStorageSync);
+ $this->filterFactory = $filter_factory;
+ }
+
+ /**
+ * Replace config:export command.
+ *
+ * @hook replace-command config:export
+ */
+ public function replaceExport($label = null, $options = ['add' => false, 'commit' => false, 'message' => self::REQ, 'destination' => self::OPT, 'diff' => false])
+ {
+ parent::export($label, $options);
+ }
+}
diff --git a/config_ignore_drush/src/Commands/ConfigIgnoreImportCommands.php b/config_ignore_drush/src/Commands/ConfigIgnoreImportCommands.php
new file mode 100644
index 0000000..130d8f9
--- /dev/null
+++ b/config_ignore_drush/src/Commands/ConfigIgnoreImportCommands.php
@@ -0,0 +1,68 @@
+<?php
+namespace Drupal\config_ignore_drush\Commands;
+
+use Drupal\Core\Config\ConfigManagerInterface;
+use Drupal\Core\Config\StorageInterface;
+use Drupal\Core\Config\TypedConfigManagerInterface;
+use Drupal\Core\Cache\CacheBackendInterface;
+use Drupal\Core\Extension\ModuleHandlerInterface;
+use Drupal\Core\Extension\ModuleInstallerInterface;
+use Drupal\Core\Extension\ThemeHandlerInterface;
+use Drupal\Core\Lock\LockBackendInterface;
+use Drupal\Core\StringTranslation\TranslationInterface;
+use Drupal\Core\Extension\ModuleExtensionList;
+use Symfony\Component\EventDispatcher\EventDispatcherInterface;
+use Drush\Drupal\Commands\config\ConfigImportCommands;
+use Drupal\config_filter\ConfigFilterStorageFactory;
+
+/**
+ * Replace config:import Drush command.
+ */
+class ConfigIgnoreImportCommands extends ConfigImportCommands
+{
+ /**
+ * @var ConfigFilterStorageFactory
+ */
+ protected $filterFactory;
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getConfigStorage() {
+ return $this->filterFactory->getFilteredStorage(parent::getConfigStorage(), ['config.storage.active']);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function __construct(
+ ConfigManagerInterface $configManager,
+ StorageInterface $configStorage,
+ StorageInterface $configStorageSync,
+ CacheBackendInterface $configCache,
+ ModuleHandlerInterface $moduleHandler,
+ // Omit type hint as it changed in https://www.drupal.org/project/drupal/issues/3161983
+ $eventDispatcher,
+ LockBackendInterface $lock,
+ TypedConfigManagerInterface $configTyped,
+ ModuleInstallerInterface $moduleInstaller,
+ ThemeHandlerInterface $themeHandler,
+ TranslationInterface $stringTranslation,
+ ModuleExtensionList $moduleExtensionList,
+ ConfigFilterStorageFactory $filterFactory
+ ){
+ parent::__construct($configManager, $configStorage, $configStorageSync, $configCache, $moduleHandler, $eventDispatcher, $lock, $configTyped, $moduleInstaller, $themeHandler, $stringTranslation, $moduleExtensionList);
+ $this->filterFactory = $filterFactory;
+ }
+
+ /**
+ * Import config from a config directory.
+ *
+ * @hook replace-command config:import
+ */
+ public function replaceImport($label = null, $options = ['preview' => 'list', 'source' => self::REQ, 'partial' => false, 'diff' => false])
+ {
+ parent::import($label, $options);
+ }
+
+}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment