You are here

function simple_sitemap_update_8204 in Simple XML sitemap 4.x

Same name and namespace in other branches
  1. 8.3 simple_sitemap.install \simple_sitemap_update_8204()
  2. 8.2 simple_sitemap.install \simple_sitemap_update_8204()

Removing entity type settings for entity types which do not have the canonical link template.

File

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

Code

function simple_sitemap_update_8204() {
  $sitemap_entity_types = \Drupal::service('entity_type.manager')
    ->getDefinitions();
  $entity_types = \Drupal::config('simple_sitemap.entity_types')
    ->get();
  unset($entity_types['_core']);
  foreach ($entity_types as $entity_type_id => $entity_type) {
    if (!isset($sitemap_entity_types[$entity_type_id]) || !$sitemap_entity_types[$entity_type_id]
      ->hasLinkTemplate('canonical')) {

      // Delete entity overrides.
      \Drupal::database()
        ->delete('simple_sitemap_entity_overrides')
        ->condition('entity_type', $entity_type_id)
        ->execute();

      // Delete entity type settings.
      unset($entity_types[$entity_type_id]);
    }
  }
  \Drupal::service('config.factory')
    ->getEditable("simple_sitemap.entity_types")
    ->setData($entity_types)
    ->save();
}