diff --git a/core/modules/config/src/Form/ConfigSingleImportForm.php b/core/modules/config/src/Form/ConfigSingleImportForm.php index 9c699ef..7255e02 100644 --- a/core/modules/config/src/Form/ConfigSingleImportForm.php +++ b/core/modules/config/src/Form/ConfigSingleImportForm.php @@ -8,7 +8,7 @@ namespace Drupal\config\Form; use Drupal\Component\Serialization\Yaml; -use Drupal\config\StorageOverrideWrapper; +use Drupal\config\StorageReplaceDataWrapper; use Drupal\Core\Config\ConfigImporter; use Drupal\Core\Config\ConfigImporterException; use Drupal\Core\Config\ConfigManagerInterface; @@ -54,7 +54,7 @@ class ConfigSingleImportForm extends ConfirmFormBase { protected $renderer; /** - * Event dispatcher. + * The event dispatcher. * * @var \Symfony\Component\EventDispatcher\EventDispatcherInterface */ @@ -119,8 +119,6 @@ class ConfigSingleImportForm extends ConfirmFormBase { /** * Constructs a new ConfigSingleImportForm. * - */ - /** * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager * The entity manager. * @param \Drupal\Core\Config\StorageInterface $config_storage @@ -335,8 +333,8 @@ public function validateForm(array &$form, FormStateInterface $form_state) { // Use ConfigImporter validation. if (!$form_state->getErrors()) { - $source_storage = new StorageOverrideWrapper($this->configStorage); - $source_storage->override($config_name, $data); + $source_storage = new StorageReplaceDataWrapper($this->configStorage); + $source_storage->replaceData($config_name, $data); $storage_comparer = new StorageComparer( $source_storage, $this->configStorage, @@ -400,14 +398,14 @@ public function submitForm(array &$form, FormStateInterface $form_state) { $sync_steps = $config_importer->initialize(); $batch = [ 'operations' => [], - 'finished' => [static::class, 'finishBatch'], + 'finished' => [ConfigSync::class, 'finishBatch'], 'title' => $this->t('Importing configuration'), 'init_message' => $this->t('Starting configuration import.'), 'progress_message' => $this->t('Completed @current step of @total.'), 'error_message' => $this->t('Configuration import has encountered an error.'), ]; foreach ($sync_steps as $sync_step) { - $batch['operations'][] = [[static::class, 'processBatch'], [$config_importer, $sync_step]]; + $batch['operations'][] = [[ConfigSync::class, 'processBatch'], [$config_importer, $sync_step]]; } batch_set($batch); @@ -422,57 +420,4 @@ public function submitForm(array &$form, FormStateInterface $form_state) { } } - /** - * Processes the config import batch and persists the importer. - * - * @param \Drupal\Core\Config\ConfigImporter $config_importer - * The batch config importer object to persist. - * @param string $sync_step - * The synchronization step to do. - * @param $context - * The batch context. - */ - public static function processBatch(ConfigImporter $config_importer, $sync_step, &$context) { - if (!isset($context['sandbox']['config_importer'])) { - $context['sandbox']['config_importer'] = $config_importer; - } - - $config_importer = $context['sandbox']['config_importer']; - $config_importer->doSyncStep($sync_step, $context); - if ($errors = $config_importer->getErrors()) { - if (!isset($context['results']['errors'])) { - $context['results']['errors'] = []; - } - $context['results']['errors'] += $errors; - } - } - - /** - * Finish batch. - * - * This function is a static function to avoid serializing the ConfigSync - * object unnecessarily. - */ - public static function finishBatch($success, $results, $operations) { - if ($success) { - if (!empty($results['errors'])) { - foreach ($results['errors'] as $error) { - drupal_set_message($error, 'error'); - \Drupal::logger('config_sync')->error($error); - } - drupal_set_message(\Drupal::translation()->translate('The configuration was imported with errors.'), 'warning'); - } - else { - drupal_set_message(\Drupal::translation()->translate('The configuration was imported successfully.')); - } - } - else { - // An error occurred. - // $operations contains the operations that remained unprocessed. - $error_operation = reset($operations); - $message = \Drupal::translation()->translate('An error occurred while processing %error_operation with arguments: @arguments', ['%error_operation' => $error_operation[0], '@arguments' => print_r($error_operation[1], TRUE)]); - drupal_set_message($message, 'error'); - } - } - } diff --git a/core/modules/config/src/StorageOverrideWrapper.php b/core/modules/config/src/StorageReplaceDataWrapper.php similarity index 62% rename from core/modules/config/src/StorageOverrideWrapper.php rename to core/modules/config/src/StorageReplaceDataWrapper.php index f551c33..c59cae8 100644 --- a/core/modules/config/src/StorageOverrideWrapper.php +++ b/core/modules/config/src/StorageReplaceDataWrapper.php @@ -2,7 +2,7 @@ /** * @file - * Contains \Drupal\config\StorageOverrideWrapper. + * Contains \Drupal\config\StorageReplaceDataWrapper. */ namespace Drupal\config; @@ -11,24 +11,24 @@ use Drupal\Core\DependencyInjection\DependencySerializationTrait; /** - * Wraps a configuration storage and allows overrides of configuration data. + * Wraps a configuration storage to allow replacing specific configuration data. */ -class StorageOverrideWrapper implements StorageInterface { +class StorageReplaceDataWrapper implements StorageInterface { use DependencySerializationTrait; /** - * The configuration storage to be cached. + * The configuration storage to be wrapped. * * @var \Drupal\Core\Config\StorageInterface */ protected $storage; /** - * The configuration overrides, keyed by configuration object name. + * The configuration replacement data, keyed by configuration object name. * * @var array */ - protected $overrideData = []; + protected $replacementData = []; /** * The storage collection. @@ -38,7 +38,7 @@ class StorageOverrideWrapper implements StorageInterface { protected $collection; /** - * Constructs a new CachedStorage. + * Constructs a new StorageReplaceDataWrapper. * * @param \Drupal\Core\Config\StorageInterface $storage * A configuration storage to be used to read and write configuration. @@ -55,15 +55,15 @@ public function __construct(StorageInterface $storage, $collection = StorageInte * {@inheritdoc} */ public function exists($name) { - return isset($this->overrideData[$this->collection][$name]) || $this->storage->exists($name); + return isset($this->replacementData[$this->collection][$name]) || $this->storage->exists($name); } /** * {@inheritdoc} */ public function read($name) { - if (isset($this->overrideData[$this->collection][$name])) { - return $this->overrideData[$this->collection][$name]; + if (isset($this->replacementData[$this->collection][$name])) { + return $this->replacementData[$this->collection][$name]; } return $this->storage->read($name); } @@ -74,8 +74,8 @@ public function read($name) { public function readMultiple(array $names) { $data = $this->storage->readMultiple(($names)); foreach ($names as $name) { - if (isset($this->overrideData[$this->collection][$name])) { - $data[$name] = $this->overrideData[$this->collection][$name]; + if (isset($this->replacementData[$this->collection][$name])) { + $data[$name] = $this->replacementData[$this->collection][$name]; } } return $data; @@ -85,8 +85,8 @@ public function readMultiple(array $names) { * {@inheritdoc} */ public function write($name, array $data) { - if (isset($this->overrideData[$this->collection][$name])) { - unset($this->overrideData[$this->collection][$name]); + if (isset($this->replacementData[$this->collection][$name])) { + unset($this->replacementData[$this->collection][$name]); } return $this->storage->write($name, $data); } @@ -95,8 +95,8 @@ public function write($name, array $data) { * {@inheritdoc} */ public function delete($name) { - if (isset($this->overrideData[$this->collection][$name])) { - unset($this->overrideData[$this->collection][$name]); + if (isset($this->replacementData[$this->collection][$name])) { + unset($this->replacementData[$this->collection][$name]); } return $this->storage->delete($name); } @@ -105,9 +105,9 @@ public function delete($name) { * {@inheritdoc} */ public function rename($name, $new_name) { - if (isset($this->overrideData[$this->collection][$name])) { - $this->overrideData[$this->collection][$new_name] = $this->overrideData[$this->collection][$name]; - unset($this->overrideData[$this->collection][$name]); + if (isset($this->replacementData[$this->collection][$name])) { + $this->replacementData[$this->collection][$new_name] = $this->replacementData[$this->collection][$name]; + unset($this->replacementData[$this->collection][$name]); } return $this->rename($name, $new_name); } @@ -133,10 +133,10 @@ public function listAll($prefix = '') { $names = $this->storage->listAll($prefix); $additional_names = []; if ($prefix === '') { - $additional_names = array_keys($this->overrideData[$this->collection]); + $additional_names = array_keys($this->replacementData[$this->collection]); } else { - foreach (array_keys($this->overrideData[$this->collection]) as $name) { + foreach (array_keys($this->replacementData[$this->collection]) as $name) { if (strpos($name, $prefix) === 0) { $additional_names[] = $name; } @@ -153,12 +153,12 @@ public function listAll($prefix = '') { */ public function deleteAll($prefix = '') { if ($prefix === '') { - $this->overrideData[$this->collection] = []; + $this->replacementData[$this->collection] = []; } else { - foreach (array_keys($this->overrideData[$this->collection]) as $name) { + foreach (array_keys($this->replacementData[$this->collection]) as $name) { if (strpos($name, $prefix) === 0) { - unset($this->overrideData[$this->collection][$name]); + unset($this->replacementData[$this->collection][$name]); } } } @@ -188,17 +188,17 @@ public function getCollectionName() { } /** - * Overrides the configuration object with the supplied data. + * Replaces the configuration object data with the supplied data. * * @param $name - * The configuration object name to override. + * The configuration object name whose data to replace. * @param array $data * The configuration data. * * @return $this */ - public function override($name, array $data) { - $this->overrideData[$this->collection][$name] = $data; + public function replaceData($name, array $data) { + $this->replacementData[$this->collection][$name] = $data; return $this; } }