View source
<?php
namespace Drupal\config_export_ignore;
use Drupal\config_filter\ConfigFilterManagerInterface;
use Drupal\config_filter\ConfigFilterStorageFactory;
use Drupal\config_split\ConfigSplitCliService;
use Drupal\Core\Config\ConfigManagerInterface;
use Drupal\Core\Config\StorageInterface;
use Drupal\Core\Config\TypedConfigManagerInterface;
use Drupal\Core\Extension\ModuleExtensionList;
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 Symfony\Component\EventDispatcher\EventDispatcherInterface;
class ConfigExportIgnoreConfigSplitService extends ConfigSplitCliService {
const FORCE_EXCLUSION_PREFIX = '~';
public function __construct(ConfigFilterManagerInterface $config_filter_manager, ConfigFilterStorageFactory $storageFactory, ConfigManagerInterface $config_manager, StorageInterface $active_storage, StorageInterface $sync_storage, EventDispatcherInterface $event_dispatcher, LockBackendInterface $lock, TypedConfigManagerInterface $config_typed, ModuleHandlerInterface $module_handler, ModuleInstallerInterface $module_installer, ThemeHandlerInterface $theme_handler, TranslationInterface $string_translation, ModuleExtensionList $moduleExtensionList) {
parent::__construct($config_filter_manager, $storageFactory, $config_manager, $active_storage, $sync_storage, $event_dispatcher, $lock, $config_typed, $module_handler, $module_installer, $theme_handler, $string_translation, $moduleExtensionList);
}
public function export(StorageInterface $storage, StorageInterface $active = NULL) {
$storage
->deleteAll();
if ($this->activeStorage
->getCollectionName() != StorageInterface::DEFAULT_COLLECTION) {
$this->activeStorage = $this->activeStorage
->createCollection(StorageInterface::DEFAULT_COLLECTION);
}
foreach ($this->activeStorage
->listAll() as $name) {
if (!self::matchConfigName($name)) {
$storage
->write($name, $this->activeStorage
->read($name));
}
}
foreach ($this->activeStorage
->getAllCollectionNames() as $collection) {
$source_collection = $this->activeStorage
->createCollection($collection);
$destination_collection = $storage
->createCollection($collection);
try {
$destination_collection
->deleteAll();
} catch (\UnexpectedValueException $exception) {
}
foreach ($source_collection
->listAll() as $name) {
if (!self::matchConfigName($name)) {
$destination_collection
->write($name, $source_collection
->read($name));
}
}
}
}
public static function matchConfigName($config_name) {
$config_ignore_settings = \Drupal::config('config_export_ignore.settings')
->get('configuration_names');
if ($config_ignore_settings) {
foreach ($config_ignore_settings as $config_ignore_setting) {
if (substr($config_ignore_setting, 0, 1) === static::FORCE_EXCLUSION_PREFIX && fnmatch(substr($config_ignore_setting, 1), $config_name)) {
return FALSE;
}
}
foreach ($config_ignore_settings as $config_ignore_setting) {
if (fnmatch($config_ignore_setting, $config_name)) {
return TRUE;
}
}
}
return FALSE;
}
}