You are here

public function Simplesitemap::removeBundleSettings in Simple XML sitemap 8.3

Removes settings for bundle or a non-bundle entity types. This is done for the currently set variants.

Parameters

string|null $entity_type_id: Limit the removal to a specific entity type.

string|null $bundle_name: Limit the removal to a specific bundle name.

Return value

$this

Throws

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException

\Drupal\Component\Plugin\Exception\PluginNotFoundException

File

src/Simplesitemap.php, line 628

Class

Simplesitemap
Class Simplesitemap @package Drupal\simple_sitemap

Namespace

Drupal\simple_sitemap

Code

public function removeBundleSettings($entity_type_id = NULL, $bundle_name = NULL) {
  if (empty($variants = $this
    ->getVariants(FALSE))) {
    return $this;
  }
  if (NULL !== $entity_type_id) {
    $bundle_name = NULL !== $bundle_name ? $bundle_name : $entity_type_id;
    foreach ($variants as $variant) {
      $this->configFactory
        ->getEditable("simple_sitemap.bundle_settings.{$variant}.{$entity_type_id}.{$bundle_name}")
        ->delete();
    }
    if (!empty($entity_ids = $this->entityHelper
      ->getEntityInstanceIds($entity_type_id, $bundle_name))) {
      $this
        ->removeEntityInstanceSettings($entity_type_id, $entity_ids);
    }
  }
  else {
    foreach ($variants as $variant) {
      $config_names = $this->configFactory
        ->listAll("simple_sitemap.bundle_settings.{$variant}.");
      foreach ($config_names as $config_name) {
        $this->configFactory
          ->getEditable($config_name)
          ->delete();
      }
    }
    $this
      ->removeEntityInstanceSettings();
  }
  return $this;
}