You are here

public function Simplesitemap::disableEntityType in Simple XML sitemap 8.3

Same name and namespace in other branches
  1. 8.2 src/Simplesitemap.php \Drupal\simple_sitemap\Simplesitemap::disableEntityType()

Disables sitemap support for an entity type. Disabling support for an entity type deletes its sitemap settings permanently and removes sitemap settings from entity forms.

Parameters

string $entity_type_id:

Return value

$this

File

src/Simplesitemap.php, line 437

Class

Simplesitemap
Class Simplesitemap @package Drupal\simple_sitemap

Namespace

Drupal\simple_sitemap

Code

public function disableEntityType($entity_type_id) {

  // Updating settings.
  $enabled_entity_types = $this
    ->getSetting('enabled_entity_types');
  if (FALSE !== ($key = array_search($entity_type_id, $enabled_entity_types))) {
    unset($enabled_entity_types[$key]);
    $this
      ->saveSetting('enabled_entity_types', array_values($enabled_entity_types));
  }

  // Deleting inclusion settings.
  $config_names = $this->configFactory
    ->listAll('simple_sitemap.bundle_settings.');
  foreach ($config_names as $config_name) {
    $config_name_parts = explode('.', $config_name);
    if ($config_name_parts[3] === $entity_type_id) {
      $this->configFactory
        ->getEditable($config_name)
        ->delete();
    }
  }

  // Deleting entity overrides.
  $this
    ->setVariants(TRUE)
    ->removeEntityInstanceSettings($entity_type_id);
  return $this;
}