public function SimplesitemapManager::addSitemapVariant in Simple XML sitemap 8.3
Parameters
string $name:
array $definition:
Return value
$this
Throws
\Drupal\Component\Plugin\Exception\PluginException
File
- src/
SimplesitemapManager.php, line 173
Class
- SimplesitemapManager
- Class SimplesitemapManager @package Drupal\simple_sitemap
Namespace
Drupal\simple_sitemapCode
public function addSitemapVariant($name, $definition = []) {
$all_variants = $this
->getSitemapVariants();
if (isset($all_variants[$name])) {
$old_variant = $all_variants[$name];
if (!empty($definition['type']) && $old_variant['type'] !== $definition['type']) {
$this
->removeSitemapVariants($name);
unset($old_variant);
}
else {
unset($old_variant['type']);
}
}
if (!isset($old_variant) && empty($definition['label'])) {
$definition['label'] = (string) $name;
}
if (!isset($old_variant) && empty($definition['type'])) {
$definition['type'] = self::DEFAULT_SITEMAP_TYPE;
}
if (isset($definition['weight'])) {
$definition['weight'] = (int) $definition['weight'];
}
elseif (!isset($old_variant)) {
$definition['weight'] = 0;
}
if (isset($old_variant)) {
$definition += $old_variant;
}
$variants = array_merge($this
->getSitemapVariants($definition['type'], FALSE), [
$name => [
'label' => $definition['label'],
'weight' => $definition['weight'],
],
]);
$this->configFactory
->getEditable('simple_sitemap.variants.' . $definition['type'])
->set('variants', $variants)
->save();
return $this;
}