public function Simplesitemap::addCustomLink in Simple XML sitemap 8.3
Same name and namespace in other branches
- 8.2 src/Simplesitemap.php \Drupal\simple_sitemap\Simplesitemap::addCustomLink()
Stores a custom path along with its settings to configuration for the currently set variants.
@todo Validate $settings and throw exceptions
Parameters
string $path:
array $settings: Settings that are not provided are supplemented by defaults.
Return value
$this
File
- src/
Simplesitemap.php, line 864
Class
- Simplesitemap
- Class Simplesitemap @package Drupal\simple_sitemap
Namespace
Drupal\simple_sitemapCode
public function addCustomLink($path, $settings = []) {
if (empty($variants = $this
->getVariants(FALSE))) {
return $this;
}
if (!(bool) $this->pathValidator
->getUrlIfValidWithoutAccessCheck($path)) {
// todo: log error.
return $this;
}
if ($path[0] !== '/') {
// todo: log error.
return $this;
}
$variant_links = $this
->getCustomLinks(NULL, FALSE, TRUE);
foreach ($variants as $variant) {
$links = [];
$link_key = 0;
if (isset($variant_links[$variant])) {
$links = $variant_links[$variant];
$link_key = count($links);
foreach ($links as $key => $link) {
if ($link['path'] === $path) {
$link_key = $key;
break;
}
}
}
$links[$link_key] = [
'path' => $path,
] + $settings;
$this->configFactory
->getEditable("simple_sitemap.custom_links.{$variant}")
->set('links', $links)
->save();
}
return $this;
}