Loading src/EnforcedConfigCollection.php +28 −0 Changes for src/EnforcedConfigCollection.php: 28 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -69,4 +69,32 @@ class EnforcedConfigCollection extends ReadOnlyEnforcedConfigCollection { } } /** * @param $enforced_configs_to_delete array of enforced config settings that need to deleted. */ public function deleteEnforcedConfigs(array $enforced_configs_to_delete) { foreach ($this->getTargetModuleCollection()->getTargetModules() as $target_module) { $registry = $target_module->getRegistry(); // Only delete enforced configs for this target module. $module_enforced_configs_to_delete = []; foreach ($enforced_configs_to_delete as $config_name => $settings) { // We skip any enforced configs destined for other target modules, as // they'll be processed on a subsequent iteration. if ($settings['target_module'] != $target_module->getMachineName()) continue; $module_enforced_configs_to_delete[$config_name] = $settings; // Drain the input array. unset($enforced_configs_to_delete[$config_name]); } $registry->deleteEnforcedConfigs($module_enforced_configs_to_delete); } // If we have any entries left in the input array, something's gone wrong. if (count($enforced_configs_to_delete)) { // @TODO: Log this? } } } src/EnforcedConfigRegistry.php +20 −0 Changes for src/EnforcedConfigRegistry.php: 20 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -102,6 +102,26 @@ class EnforcedConfigRegistry extends ReadOnlyEnforcedConfigRegistry { } /** * @param $enforced_configs_to_delete array of enforced config settings to delete. */ public function deleteEnforcedConfigs(array $enforced_configs_to_delete) { if (empty($enforced_configs_to_delete)) return; $registry_config = $this->configFactory->getEditable($this->getConfigName()); foreach ($enforced_configs_to_delete as $config_name => $settings) { // Remove the enforced config settings. $registry_config->clear(self::encode($config_name)); } // @TODO: Also delete the config files from disk? // Save the updated registry config. $registry_config->save(); // @TODO: Log this? } /** * Delete this registry of enforced configs. */ Loading src/Form/EnforcedConfigs.php +17 −6 Changes for src/Form/EnforcedConfigs.php: 17 added lines, 6 removed lines. Original line number Diff line number Diff line Loading @@ -92,15 +92,26 @@ class EnforcedConfigs extends FormBase { * Delete selected enforced config settings. */ protected function deleteEnforcedConfigs() { $this->enforcedConfig = new EnforcedConfig(); $enforced_configs = (new EnforcedConfigCollection())->getEnforcedConfigs(); $enforced_configs_to_delete = $this->getEnforcedConfigsToDelete(); (new EnforcedConfigCollection())->deleteEnforcedConfigs($enforced_configs_to_delete); $this->messenger()->addMessage( $this->t('Deleted enforcement settings for: %config_list', [ '%config_list' => $this->renderHtmlList(array_keys($enforced_configs_to_delete)), ]) ); } /** * Return an array of enforced configs to delete. */ protected function getEnforcedConfigsToDelete() { $enforced_configs = (new EnforcedConfigCollection())->getEnforcedConfigs(); $enforced_configs_to_delete = []; foreach ($this->getSelectedConfigs() as $config_name) { $this->enforcedConfig ->setConfigName($config_name) ->setTargetModule($enforced_configs[$config_name]['target_module']) ->clear(); $enforced_configs_to_delete[$config_name] = $enforced_configs[$config_name]; } return $enforced_configs_to_delete; } /** Loading Loading
src/EnforcedConfigCollection.php +28 −0 Changes for src/EnforcedConfigCollection.php: 28 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -69,4 +69,32 @@ class EnforcedConfigCollection extends ReadOnlyEnforcedConfigCollection { } } /** * @param $enforced_configs_to_delete array of enforced config settings that need to deleted. */ public function deleteEnforcedConfigs(array $enforced_configs_to_delete) { foreach ($this->getTargetModuleCollection()->getTargetModules() as $target_module) { $registry = $target_module->getRegistry(); // Only delete enforced configs for this target module. $module_enforced_configs_to_delete = []; foreach ($enforced_configs_to_delete as $config_name => $settings) { // We skip any enforced configs destined for other target modules, as // they'll be processed on a subsequent iteration. if ($settings['target_module'] != $target_module->getMachineName()) continue; $module_enforced_configs_to_delete[$config_name] = $settings; // Drain the input array. unset($enforced_configs_to_delete[$config_name]); } $registry->deleteEnforcedConfigs($module_enforced_configs_to_delete); } // If we have any entries left in the input array, something's gone wrong. if (count($enforced_configs_to_delete)) { // @TODO: Log this? } } }
src/EnforcedConfigRegistry.php +20 −0 Changes for src/EnforcedConfigRegistry.php: 20 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -102,6 +102,26 @@ class EnforcedConfigRegistry extends ReadOnlyEnforcedConfigRegistry { } /** * @param $enforced_configs_to_delete array of enforced config settings to delete. */ public function deleteEnforcedConfigs(array $enforced_configs_to_delete) { if (empty($enforced_configs_to_delete)) return; $registry_config = $this->configFactory->getEditable($this->getConfigName()); foreach ($enforced_configs_to_delete as $config_name => $settings) { // Remove the enforced config settings. $registry_config->clear(self::encode($config_name)); } // @TODO: Also delete the config files from disk? // Save the updated registry config. $registry_config->save(); // @TODO: Log this? } /** * Delete this registry of enforced configs. */ Loading
src/Form/EnforcedConfigs.php +17 −6 Changes for src/Form/EnforcedConfigs.php: 17 added lines, 6 removed lines. Original line number Diff line number Diff line Loading @@ -92,15 +92,26 @@ class EnforcedConfigs extends FormBase { * Delete selected enforced config settings. */ protected function deleteEnforcedConfigs() { $this->enforcedConfig = new EnforcedConfig(); $enforced_configs = (new EnforcedConfigCollection())->getEnforcedConfigs(); $enforced_configs_to_delete = $this->getEnforcedConfigsToDelete(); (new EnforcedConfigCollection())->deleteEnforcedConfigs($enforced_configs_to_delete); $this->messenger()->addMessage( $this->t('Deleted enforcement settings for: %config_list', [ '%config_list' => $this->renderHtmlList(array_keys($enforced_configs_to_delete)), ]) ); } /** * Return an array of enforced configs to delete. */ protected function getEnforcedConfigsToDelete() { $enforced_configs = (new EnforcedConfigCollection())->getEnforcedConfigs(); $enforced_configs_to_delete = []; foreach ($this->getSelectedConfigs() as $config_name) { $this->enforcedConfig ->setConfigName($config_name) ->setTargetModule($enforced_configs[$config_name]['target_module']) ->clear(); $enforced_configs_to_delete[$config_name] = $enforced_configs[$config_name]; } return $enforced_configs_to_delete; } /** Loading