function simple_sitemap_update_8403 in Simple XML sitemap 4.x
Migrate the default_hreflang sitemap type and its variants to new configuration entities.
File
- ./
simple_sitemap.install, line 844 - Module install and update procedures.
Code
function simple_sitemap_update_8403() {
// Create default_hreflang sitemap type.
$type_storage = \Drupal::entityTypeManager()
->getStorage('simple_sitemap_type');
if ($type_storage
->load('default_hreflang') === NULL) {
$type_storage
->create([
'id' => 'default_hreflang',
'label' => 'Default hreflang',
'description' => 'The default hreflang sitemap type.',
'sitemap_generator' => 'default',
'url_generators' => [
'custom',
'entity',
'entity_menu_link_content',
'arbitrary',
],
])
->save();
}
// Migrate variants of default_hreflang sitemap type.
$config_factory = \Drupal::configFactory();
$sitemap_storage = \Drupal::entityTypeManager()
->getStorage('simple_sitemap');
$old_variants_config = $config_factory
->get('simple_sitemap.variants.default_hreflang');
foreach ($old_variants_config
->get('variants') as $variant_id => $variant_definition) {
if ($sitemap_storage
->load(substr($variant_id, 0, 32)) === NULL) {
$sitemap_storage
->create([
'id' => substr($variant_id, 0, 32),
'label' => $variant_definition['label'] ?? $variant_id,
'type' => 'default_hreflang',
'weight' => $variant_definition['weight'] ?? 0,
])
->save();
}
}
foreach ($config_factory
->listAll('simple_sitemap.variants.') as $config) {
$config_factory
->getEditable($config)
->delete();
}
\Drupal::service('simple_sitemap.queue_worker')
->deleteQueue();
\Drupal\simple_sitemap\Entity\SimpleSitemap::purgeContent();
return t('All variants belonging to the built-in "Default hreflang" sitemap type have been converted to entities. Custom sitemap types added via plugins will have to be recreated manually. See simple_sitemap.type.default_hreflang.yml. The sitemaps need to be regenerated now.');
}