Problem/Motivation
After adding a couple of new domains to the existing list of domains, we're now getting the following error when trying to deploy:
The import failed due to the following reasons:
Deleted and replaced configuration entity "simple_sitemap.type.example_com"
Steps to reproduce
- Create a new domain and export out the configs
- Try to deploy the config
- Notice that when running `drush cim -y` you get the above error
Proposed resolution
The error happens when an entity, in our case, the `simple_sitemap.type.example_com` config entity, you are trying to create already exists.
After some debugging, we found out that the error is emanating from `domain_simple_sitemap_domain_insert()`. In `addSitemapVariant()` it tries to create the sitemap type which is already exported in config:
// Create a new sitemap type for the domain.
$type_storage = \Drupal::entityTypeManager()->getStorage('simple_sitemap_type');
if ($type_storage->load($domain->id()) === NULL) {
$domain_sitemap = $type_storage->create([
'id' => $domain->id(),
'label' => $domain->label() . ' sitemap',
'description' => 'Sitemap type for domain: ' . $domain->label(),
'sitemap_generator' => 'default',
'url_generators' => [
'domain_entity',
'custom',
'entity',
'entity_menu_link_content',
'arbitrary',
],
]);
// Set the domain to the sitemap type via third party settings.
$domain_sitemap->setThirdPartySetting('domain_simple_sitemap', 'sitemap_domain', $domain->id());
// Save our new sitemap type.
$domain_sitemap->save();
}
So, this hook is running too early during configuration sync.
Remaining tasks
As mentioned here, we'll need to add the following in `domain_simple_sitemap_domain_insert()`:
if (\Drupal::isConfigSyncing()) {
// Do not change data while config import in progress.
return;
}
User interface changes
None
API changes
None
Data model changes
None