public function ConfigUpdater::revert in Commerce Core 8.2
Reverts configuration to the values from extension storage.
Parameters
string[] $config_names: The configuration names.
bool $skip_modified: Whether to skip modified configuration.
Return value
\Drupal\commerce\Config\ConfigUpdateResult The result.
Overrides ConfigUpdaterInterface::revert
File
- src/
Config/ ConfigUpdater.php, line 126
Class
- ConfigUpdater
- Default implementation of the ConfigUpdaterInterface.
Namespace
Drupal\commerce\ConfigCode
public function revert(array $config_names, $skip_modified = TRUE) {
$succeeded = [];
$failed = [];
foreach ($config_names as $config_name) {
$config_data = $this
->loadFromExtension($config_name);
if (!$config_data) {
$failed[$config_name] = $this
->t('@config does not exist in extension storage', [
'@config' => $config_name,
]);
continue;
}
$active_config_data = $this
->loadFromActive($config_name);
if (!$active_config_data) {
$succeeded[$config_name] = $this
->t('Skipped: @config does not exist in active storage', [
'@config' => $config_name,
]);
continue;
}
if ($this
->isModified($active_config_data) && $skip_modified) {
$succeeded[$config_name] = $this
->t('Skipped: @config was not reverted because it was modified by the user', [
'@config' => $config_name,
]);
continue;
}
$config_type = $this
->getConfigType($config_name);
if ($config_type == 'system.simple') {
$this->configFactory
->getEditable($config_name)
->setData($config_data)
->save();
}
else {
/** @var \Drupal\Core\Config\Entity\ConfigEntityTypeInterface $entity_type */
$entity_type = $this->entityTypeManager
->getDefinition($config_type);
$id = substr($config_name, strlen($entity_type
->getConfigPrefix()) + 1);
/** @var \Drupal\Core\Config\Entity\ConfigEntityStorageInterface $entity_storage */
$entity_storage = $this->entityTypeManager
->getStorage($config_type);
/** @var \Drupal\Core\Config\Entity\ConfigEntityInterface $entity */
$entity = $entity_storage
->load($id);
// The UUID must remain unchanged between updates.
$uuid = $entity
->uuid();
$entity = $entity_storage
->updateFromStorageRecord($entity, $config_data);
$entity
->set('uuid', $uuid);
$entity
->save();
}
$succeeded[$config_name] = $this
->t('@config was successfully reverted', [
'@config' => $config_name,
]);
}
return new ConfigUpdateResult($succeeded, $failed);
}