public function ConfigDevelAutoImportSubscriber::importOne in Configuration development 8
Parameters
string $filename:
string $original_hash:
Return value
bool
1 call to ConfigDevelAutoImportSubscriber::importOne()
- ConfigDevelAutoImportSubscriber::autoImportConfig in src/
EventSubscriber/ ConfigDevelAutoImportSubscriber.php - Reinstall changed config files.
File
- src/
EventSubscriber/ ConfigDevelAutoImportSubscriber.php, line 45
Class
Namespace
Drupal\config_devel\EventSubscriberCode
public function importOne($filename, $original_hash = '', $contents = '') {
// TODO: use the config_devel.importer_exporter service.
$hash = '';
if (!$contents && !($contents = @file_get_contents($filename))) {
return $hash;
}
$needs_import = TRUE;
if ($original_hash) {
$hash = Crypt::hashBase64($contents);
if ($hash == $original_hash) {
$needs_import = FALSE;
}
}
if ($needs_import) {
$data = (new InstallStorage())
->decode($contents);
$config_name = basename($filename, '.yml');
$entity_type_id = $this->configManager
->getEntityTypeIdByName($config_name);
if ($entity_type_id) {
$entity_storage = $this
->getStorage($entity_type_id);
$entity_id = $this
->getEntityId($entity_storage, $config_name);
$entity_type = $entity_storage
->getEntityType();
$id_key = $entity_type
->getKey('id');
$data[$id_key] = $entity_id;
/** @var \Drupal\Core\Config\Entity\ConfigEntityInterface $entity */
$entity = $entity_storage
->createFromStorageRecord($data);
if ($existing_entity = $entity_storage
->load($entity_id)) {
$entity
->set('uuid', $existing_entity
->uuid())
->enforceIsNew(FALSE);
}
$entity_storage
->save($entity);
}
else {
$this->configFactory
->getEditable($config_name)
->setData($data)
->save();
}
}
return $hash;
}