You are here

function simple_sitemap_update_8205 in Simple XML sitemap 8.2

Same name and namespace in other branches
  1. 8.3 simple_sitemap.install \simple_sitemap_update_8205()
  2. 4.x simple_sitemap.install \simple_sitemap_update_8205()

Splitting simple_sitemap.entity_types into individual configuration objects for each bundle.

File

./simple_sitemap.install, line 275
Module install and update procedures.

Code

function simple_sitemap_update_8205() {
  $entity_types = \Drupal::config('simple_sitemap.entity_types')
    ->get();
  unset($entity_types['_core']);
  $enabled_entity_types = [];
  foreach ($entity_types as $entity_type_id => $bundles) {
    $enabled_entity_types[] = $entity_type_id;
    foreach ($bundles as $bundle_name => $bundle_settings) {
      \Drupal::service('config.factory')
        ->getEditable("simple_sitemap.bundle_settings.{$entity_type_id}.{$bundle_name}")
        ->setData($bundle_settings)
        ->save();
    }
  }

  // Add enabled entity type settings.
  \Drupal::service('config.factory')
    ->getEditable('simple_sitemap.settings')
    ->set('enabled_entity_types', $enabled_entity_types)
    ->save();

  // Remove old configuration object.
  \Drupal::service('config.factory')
    ->getEditable('simple_sitemap.entity_types')
    ->delete();
}