public function CustomLinkManager::remove in Simple XML sitemap 4.x
Removes custom links from currently set variants.
Parameters
array|string|null $paths: Limits the removal to certain paths.
Return value
\Drupal\simple_sitemap\Manager\CustomLinkManager
File
- src/
Manager/ CustomLinkManager.php, line 157
Class
- CustomLinkManager
- Class CustomLinkManager
Namespace
Drupal\simple_sitemap\ManagerCode
public function remove($paths = NULL) : CustomLinkManager {
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
->get(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;
}