You are here

public function Simplesitemap::removeCustomLinks in Simple XML sitemap 8.3

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

Removes custom links from currently set variants.

Parameters

array|null $paths: Limits the removal to certain paths.

Return value

$this

File

src/Simplesitemap.php, line 966

Class

Simplesitemap
Class Simplesitemap @package Drupal\simple_sitemap

Namespace

Drupal\simple_sitemap

Code

public function removeCustomLinks($paths = NULL) {
  if (empty($variants = $this
    ->getVariants(FALSE))) {
    return $this;
  }
  if (NULL === $paths) {
    foreach ($variants as $variant) {
      $this->configFactory
        ->getEditable("simple_sitemap.custom_links.{$variant}")
        ->delete();
    }
  }
  else {
    $variant_links = $this
      ->getCustomLinks(NULL, FALSE, TRUE);
    foreach ($variant_links as $variant => $links) {
      $custom_links = $links;
      $save = FALSE;
      foreach ((array) $paths as $path) {
        foreach ($custom_links as $key => $link) {
          if ($link['path'] === $path) {
            unset($custom_links[$key]);
            $save = TRUE;
            break 2;
          }
        }
      }
      if ($save) {
        $this->configFactory
          ->getEditable("simple_sitemap.custom_links.{$variant}")
          ->set('links', array_values($custom_links))
          ->save();
      }
    }
  }
  return $this;
}