You are here

public function EntityManager::removeBundleSettings in Simple XML sitemap 4.x

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

\Drupal\simple_sitemap\Manager\EntityManager

Throws

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException

\Drupal\Component\Plugin\Exception\PluginNotFoundException

File

src/Manager/EntityManager.php, line 294

Class

EntityManager
Class EntityManager

Namespace

Drupal\simple_sitemap\Manager

Code

public function removeBundleSettings(?string $entity_type_id = NULL, ?string $bundle_name = NULL) : EntityManager {
  if (empty($variants = $this
    ->getVariants(FALSE))) {
    return $this;
  }
  if (NULL !== $entity_type_id) {
    $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;
}