public function ConfigReverter::import in Configuration Update Manager 8
Imports configuration from extension storage to active storage.
This action triggers a ConfigRevertInterface::IMPORT event if the configuration could be imported.
Parameters
string $type: The type of configuration.
string $name: The name of the config item, without the prefix.
Return value
bool TRUE if the operation succeeded; FALSE if the configuration could not be found to import. May also throw exceptions if there is a problem during saving the configuration.
Overrides ConfigRevertInterface::import
See also
\Drupal\config_update\ConfigRevertInterface::IMPORT
File
- src/
ConfigReverter.php, line 89
Class
- ConfigReverter
- Provides methods related to config reverting, deleting, and importing.
Namespace
Drupal\config_updateCode
public function import($type, $name) {
// Read the config from the file. Note: Do not call getFromExtension() here
// because we need $full_name below.
$full_name = $this
->getFullName($type, $name);
$value = FALSE;
if ($full_name) {
$value = $this->extensionConfigStorage
->read($full_name);
if (!$value) {
$value = $this->extensionOptionalConfigStorage
->read($full_name);
}
}
if (!$value) {
return FALSE;
}
// Save it as a new config entity or simple config.
if ($type == 'system.simple') {
$this->configFactory
->getEditable($full_name)
->setData($value)
->save();
}
else {
$entity_storage = $this->entityManager
->getStorage($type);
$entity = $entity_storage
->createFromStorageRecord($value);
$entity
->save();
}
// Trigger an event notifying of this change.
$event = new ConfigRevertEvent($type, $name);
$this->dispatcher
->dispatch(ConfigRevertInterface::IMPORT, $event);
return TRUE;
}