Commit f4d4706a authored by gbyte.co's avatar gbyte.co

Rename variable to for clarity

parent 9873b7e2
......@@ -22,6 +22,6 @@ function simple_sitemap_drush_command() {
* Regenerate sitemap for all languages.
*/
function drush_simple_sitemap_generate() {
$sitemap = \Drupal::service('simple_sitemap.generator');
$sitemap->generateSitemap('drush');
$generator = \Drupal::service('simple_sitemap.generator');
$generator->generateSitemap('drush');
}
......@@ -21,8 +21,8 @@ function simple_sitemap_requirements($phase) {
switch($phase) {
case 'runtime':
$sitemap = \Drupal::service('simple_sitemap.generator');
$generated_ago = $sitemap->getGeneratedAgo();
$generator = \Drupal::service('simple_sitemap.generator');
$generated_ago = $generator->getGeneratedAgo();
if (!$generated_ago) {
$value = t('Not available');
$description = t("The sitemap has not been generated yet. Run cron, or <a href='@generate'>generate</a> the sitemap manually.", ['@generate' => $GLOBALS['base_url'] . '/admin/config/search/simplesitemap']);
......@@ -79,8 +79,8 @@ function simple_sitemap_schema() {
* Implements hook_install().
*/
function simple_sitemap_install() {
$sitemap = \Drupal::service('simple_sitemap.generator');
$sitemap->generateSitemap('nobatch');
$generator = \Drupal::service('simple_sitemap.generator');
$generator->generateSitemap('nobatch');
$base_url = $GLOBALS['base_url'];
drupal_set_message(t("You can now include content into the <a href='@sitemap_url' target='_blank'>XML sitemap</a> by visiting the corresponding entity type edit pages (e.g. <a href='@content_type_url' target='_blank'>node type edit pages</a>) These settings can then be overridden for single entities.<br/> Support for additional entity types and custom links can be added on <a href='@config_url' target='_blank'>the module's configuration pages</a>.", ['@sitemap_url' => "$base_url/sitemap.xml", '@content_type_url' => "$base_url/admin/structure/types", '@config_url' => "$base_url/admin/config/search/simplesitemap"]));
}
......
......@@ -67,25 +67,25 @@ function simple_sitemap_entity_form_submit($form, &$form_state) {
// Only make changes in DB if sitemap settings actually changed.
if (Form::valuesChanged($form, $values)) {
$sitemap = \Drupal::service('simple_sitemap.generator');
$generator = \Drupal::service('simple_sitemap.generator');
$f = new Form($form_state);
switch ($f->entityCategory) {
case 'bundle':
$f->bundleName = !empty($f->bundleName) ? $f->bundleName : $f->getFormEntityId();
$sitemap->setBundleSettings($f->entityTypeId, $f->bundleName, ['index' => $values['simple_sitemap_index_content'], 'priority' => $values['simple_sitemap_priority']]);
$generator->setBundleSettings($f->entityTypeId, $f->bundleName, ['index' => $values['simple_sitemap_index_content'], 'priority' => $values['simple_sitemap_priority']]);
break;
case 'instance':
$f->instanceId = !empty($f->instanceId) ? $f->instanceId : $f->getFormEntityId();
$sitemap->setEntityInstanceSettings($f->entityTypeId, $f->instanceId, ['index' => $values['simple_sitemap_index_content'], 'priority' => $values['simple_sitemap_priority']]);
$generator->setEntityInstanceSettings($f->entityTypeId, $f->instanceId, ['index' => $values['simple_sitemap_index_content'], 'priority' => $values['simple_sitemap_priority']]);
break;
}
// Regenerate sitemaps according to user setting.
if ($values['simple_sitemap_regenerate_now']) {
$sitemap->generateSitemap();
$generator->generateSitemap();
}
}
}
......@@ -94,9 +94,9 @@ function simple_sitemap_entity_form_submit($form, &$form_state) {
* Implements hook_cron.
*/
function simple_sitemap_cron() {
$sitemap = \Drupal::service('simple_sitemap.generator');
if ($sitemap->getSetting('cron_generate')) {
$sitemap->generateSitemap('backend');
$generator = \Drupal::service('simple_sitemap.generator');
if ($generator->getSetting('cron_generate')) {
$generator->generateSitemap('backend');
}
}
......@@ -108,13 +108,13 @@ function simple_sitemap_cron() {
* @todo Not working for menu bundles, as they are technically not bundles. Implement hook_menu_delete().
*/
function simple_sitemap_entity_bundle_delete($entity_type_id, $bundle) {
$sitemap = \Drupal::service('simple_sitemap.generator');
$entity_types = $sitemap->getConfig('entity_types');
$generator = \Drupal::service('simple_sitemap.generator');
$entity_types = $generator->getConfig('entity_types');
if (isset($entity_types[$entity_type_id][$bundle])) {
unset($entity_types[$entity_type_id][$bundle]);
$sitemap->saveConfig('entity_types', $entity_types);
$generator->saveConfig('entity_types', $entity_types);
$message = t("You may want to <a href='@url'>regenerate</a> your XML sitemap now.", ['@url' => $GLOBALS['base_url'] . '/admin/config/search/simplesitemap']);
if ($sitemap->getSetting('cron_generate')) {
if ($generator->getSetting('cron_generate')) {
$message .= '</br>' . t('Otherwise the sitemap will be regenerated on the next cron run.');
}
// drupal_set_message($message); // todo: Commented out, as html code is visible.
......@@ -127,14 +127,14 @@ function simple_sitemap_entity_bundle_delete($entity_type_id, $bundle) {
* Removes settings of the removed entity.
*/
function simple_sitemap_entity_delete(Drupal\Core\Entity\EntityInterface $entity) {
$sitemap = \Drupal::service('simple_sitemap.generator');
$entity_types = $sitemap->getConfig('entity_types');
$generator = \Drupal::service('simple_sitemap.generator');
$entity_types = $generator->getConfig('entity_types');
$entity_type_id = $entity->getEntityTypeId();
$bundle_name = !empty($entity->bundle()) ? $entity->bundle() : $entity_type_id;
$bundle_name = $bundle_name == 'menu_link_content'&& method_exists($entity, 'getMenuName') ? $entity->getMenuName() : $bundle_name; // Menu fix.
if (isset($entity_types[$entity_type_id][$bundle_name]['entities'][$entity->id()])) {
unset($entity_types[$entity_type_id][$bundle_name]['entities'][$entity->id()]);
$sitemap->saveConfig('entity_types', $entity_types);
$generator->saveConfig('entity_types', $entity_types);
}
}
......@@ -21,30 +21,30 @@ class SimplesitemapController extends ControllerBase {
*
* @var \Drupal\simple_sitemap\Simplesitemap
*/
protected $sitemapGenerator;
protected $generator;
/**
* SimplesitemapController constructor.
*
* @param \Drupal\simple_sitemap\Simplesitemap $sitemap_generator
* @param \Drupal\simple_sitemap\Simplesitemap $generator
* The sitemap generator.
*/
public function __construct($sitemap_generator) {
$this->sitemapGenerator = $sitemap_generator;
public function __construct($generator) {
$this->generator = $generator;
}
/**
* Returns the whole sitemap, a requested sitemap chunk, or the sitemap index file.
*
* @param int $sitemap_id
* @param int $chunk_id
* Optional ID of the sitemap chunk. If none provided, the first chunk or
* the sitemap index is fetched.
*
* @return object Response
* Returns an XML response.
*/
public function getSitemap($sitemap_id = NULL) {
$output = $this->sitemapGenerator->getSitemap($sitemap_id);
public function getSitemap($chunk_id = NULL) {
$output = $this->generator->getSitemap($chunk_id);
$output = !$output ? '' : $output;
// Display sitemap with correct xml header.
......@@ -60,5 +60,4 @@ class SimplesitemapController extends ControllerBase {
public static function create(ContainerInterface $container) {
return new static($container->get('simple_sitemap.generator'));
}
}
......@@ -22,7 +22,7 @@ class Form {
public $instanceId;
private $formState;
private $sitemap;
private $generator;
private static $allowedFormOperations = ['default', 'edit', 'add'];
private static $valuesToCheck = ['simple_sitemap_index_content', 'simple_sitemap_priority', 'simple_sitemap_regenerate_now'];
......@@ -40,7 +40,7 @@ class Form {
$this->formState = $form_state;
$this->entityCategory = NULL;
$this->alteringForm = TRUE;
$this->sitemap = \Drupal::service('simple_sitemap.generator');
$this->generator = \Drupal::service('simple_sitemap.generator');
$this->getEntityData();
}
......@@ -54,12 +54,12 @@ class Form {
$this->alteringForm = FALSE;
// Do not alter the form if entity is not enabled in sitemap settings.
elseif (!$this->sitemap->entityTypeIsEnabled($this->entityTypeId))
elseif (!$this->generator->entityTypeIsEnabled($this->entityTypeId))
$this->alteringForm = FALSE;
// Do not alter the form, if sitemap is disabled for the entity type of this entity instance.
elseif ($this->entityCategory == 'instance'
&& !$this->sitemap->bundleIsIndexed($this->entityTypeId, $this->bundleName))
&& !$this->generator->bundleIsIndexed($this->entityTypeId, $this->bundleName))
$this->alteringForm = FALSE;
}
......@@ -86,7 +86,7 @@ class Form {
'#description' => t('This setting will regenerate the whole sitemap including the above changes.'),
'#default_value' => FALSE,
];
if ($this->sitemap->getSetting('cron_generate')) {
if ($this->generator->getSetting('cron_generate')) {
$form_fragment['simple_sitemap_regenerate_now']['#description'] .= '</br>' . t('Otherwise the sitemap will be regenerated on the next cron run.');
}
}
......@@ -95,11 +95,11 @@ class Form {
$prefix = $multiple ? $this->entityTypeId . '_' : '';
if ($this->entityCategory == 'instance') {
$bundle_settings = $this->sitemap->getBundleSettings($this->entityTypeId, $this->bundleName);
$settings = !is_null($this->instanceId) ? $this->sitemap->getEntityInstanceSettings($this->entityTypeId, $this->instanceId) : $bundle_settings;
$bundle_settings = $this->generator->getBundleSettings($this->entityTypeId, $this->bundleName);
$settings = !is_null($this->instanceId) ? $this->generator->getEntityInstanceSettings($this->entityTypeId, $this->instanceId) : $bundle_settings;
}
else {
$settings = $this->sitemap->getBundleSettings($this->entityTypeId, $this->bundleName);
$settings = $this->generator->getBundleSettings($this->entityTypeId, $this->bundleName);
}
$index = isset($settings['index']) ? $settings['index'] : 0;
$priority = isset($settings['priority']) ? $settings['priority'] : self::PRIORITY_DEFAULT;
......
......@@ -35,9 +35,9 @@ class SimplesitemapCustomLinksForm extends ConfigFormBase {
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$sitemap = \Drupal::service('simple_sitemap.generator');
$generator = \Drupal::service('simple_sitemap.generator');
$setting_string = '';
foreach ($sitemap->getConfig('custom') as $custom_link) {
foreach ($generator->getConfig('custom') as $custom_link) {
$setting_string .= isset($custom_link['priority'])
? $custom_link['path'] . ' ' . Form::formatPriority($custom_link['priority'])
: $custom_link['path'];
......@@ -90,17 +90,17 @@ class SimplesitemapCustomLinksForm extends ConfigFormBase {
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$sitemap = \Drupal::service('simple_sitemap.generator');
$generator = \Drupal::service('simple_sitemap.generator');
$custom_link_config = $this->getCustomLinkConfig($form_state->getValue('custom_links'));
$sitemap->removeCustomLinks();
$generator->removeCustomLinks();
foreach ($custom_link_config as $link_config) {
$sitemap->addCustomLink($link_config['path'], $link_config);
$generator->addCustomLink($link_config['path'], $link_config);
}
parent::submitForm($form, $form_state);
// Regenerate sitemaps according to user setting.
if ($form_state->getValue('simple_sitemap_regenerate_now')) {
$sitemap->generateSitemap();
$generator->generateSitemap();
}
}
......
......@@ -36,7 +36,7 @@ class SimplesitemapEntitiesForm extends ConfigFormBase {
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$sitemap = \Drupal::service('simple_sitemap.generator');
$generator = \Drupal::service('simple_sitemap.generator');
$form['simple_sitemap_entities']['entities'] = [
'#title' => t('Sitemap entities'),
......@@ -59,13 +59,13 @@ class SimplesitemapEntitiesForm extends ConfigFormBase {
$form['simple_sitemap_entities']['entities'][$entity_type_id] = [
'#type' => 'details',
'#title' => $entity_type_label,
'#open' => $sitemap->entityTypeIsEnabled($entity_type_id),
'#open' => $generator->entityTypeIsEnabled($entity_type_id),
];
$form['simple_sitemap_entities']['entities'][$entity_type_id][$entity_type_id . '_enabled'] = [
'#type' => 'checkbox',
'#title' => t('Enable @entity_type_label <em>(@entity_type_id)</em> support', ['@entity_type_label' => strtolower($entity_type_label), '@entity_type_id' => $entity_type_id]),
'#description' => t('Sitemap settings for this entity type can be set on its bundle pages and overridden on its entity pages.'),
'#default_value' => $sitemap->entityTypeIsEnabled($entity_type_id),
'#default_value' => $generator->entityTypeIsEnabled($entity_type_id),
];
$form['#attached']['drupalSettings']['simple_sitemap']['all_entities'][] = str_replace('_', '-', $entity_type_id);
if (Simplesitemap::entityTypeIsAtomic($entity_type_id)) {
......@@ -85,29 +85,29 @@ class SimplesitemapEntitiesForm extends ConfigFormBase {
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$sitemap = \Drupal::service('simple_sitemap.generator');
$generator = \Drupal::service('simple_sitemap.generator');
$values = $form_state->getValues();
foreach($values as $field_name => $value) {
if (substr($field_name, -strlen('_enabled')) == '_enabled') {
$entity_type_id = substr($field_name, 0, -8);
if ($value) {
$sitemap->enableEntityType($entity_type_id);
$generator->enableEntityType($entity_type_id);
if (Simplesitemap::entityTypeIsAtomic($entity_type_id)) {
$sitemap->setBundleSettings($entity_type_id, $entity_type_id, [
$generator->setBundleSettings($entity_type_id, $entity_type_id, [
'index' => TRUE,
'priority' => $values[$entity_type_id . '_simple_sitemap_priority']
]);
}
}
else
$sitemap->disableEntityType($entity_type_id);
$generator->disableEntityType($entity_type_id);
}
}
parent::submitForm($form, $form_state);
// Regenerate sitemaps according to user setting.
if ($form_state->getValue('simple_sitemap_regenerate_now')) {
$sitemap->generateSitemap();
$generator->generateSitemap();
}
}
}
......@@ -34,7 +34,7 @@ class SimplesitemapSettingsForm extends ConfigFormBase {
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$sitemap = \Drupal::service('simple_sitemap.generator');
$generator = \Drupal::service('simple_sitemap.generator');
$form['simple_sitemap_settings']['#prefix'] = "<div class='description'>" .t("If you would like to say thanks and support the development of this module, a <a target='_blank' href='@url'>donation</a> is always appreciated.", ['@url' => 'https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=5AFYRSBLGSC3W']) . "</div>";
......@@ -60,7 +60,7 @@ class SimplesitemapSettingsForm extends ConfigFormBase {
'#type' => 'checkbox',
'#title' => t('Regenerate the sitemap on every cron run'),
'#description' => t('Uncheck this if you intend to only regenerate the sitemap manually or via drush.'),
'#default_value' => $sitemap->getSetting('cron_generate'),
'#default_value' => $generator->getSetting('cron_generate'),
];
$form['simple_sitemap_settings']['advanced'] = [
......@@ -72,7 +72,7 @@ class SimplesitemapSettingsForm extends ConfigFormBase {
'#type' => 'checkbox',
'#title' => t('Exclude duplicate links'),
'#description' => t('Uncheck this to significantly speed up the sitemap generation process on a huge site (more than 20 000 indexed entities).'),
'#default_value' => $sitemap->getSetting('remove_duplicates'),
'#default_value' => $generator->getSetting('remove_duplicates'),
];
$form['simple_sitemap_settings']['advanced']['max_links'] = [
......@@ -81,7 +81,7 @@ class SimplesitemapSettingsForm extends ConfigFormBase {
'#type' => 'textfield',
'#maxlength' => 5,
'#size' => 5,
'#default_value' => $sitemap->getSetting('max_links'),
'#default_value' => $generator->getSetting('max_links'),
];
$form['simple_sitemap_settings']['advanced']['batch_process_limit'] = [
......@@ -90,7 +90,7 @@ class SimplesitemapSettingsForm extends ConfigFormBase {
'#type' => 'textfield',
'#maxlength' => 5,
'#size' => 5,
'#default_value' => $sitemap->getSetting('batch_process_limit'),
'#default_value' => $generator->getSetting('batch_process_limit'),
];
return parent::buildForm($form, $form_state);
......@@ -117,16 +117,16 @@ class SimplesitemapSettingsForm extends ConfigFormBase {
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$sitemap = \Drupal::service('simple_sitemap.generator');
$sitemap->saveSetting('max_links', $form_state->getValue('max_links'));
$sitemap->saveSetting('cron_generate', $form_state->getValue('cron_generate'));
$sitemap->saveSetting('remove_duplicates', $form_state->getValue('remove_duplicates'));
$sitemap->saveSetting('batch_process_limit', $form_state->getValue('batch_process_limit'));
$generator = \Drupal::service('simple_sitemap.generator');
$generator->saveSetting('max_links', $form_state->getValue('max_links'));
$generator->saveSetting('cron_generate', $form_state->getValue('cron_generate'));
$generator->saveSetting('remove_duplicates', $form_state->getValue('remove_duplicates'));
$generator->saveSetting('batch_process_limit', $form_state->getValue('batch_process_limit'));
parent::submitForm($form, $form_state);
}
public function generateSitemap(array &$form, FormStateInterface $form_state) {
$sitemap = \Drupal::service('simple_sitemap.generator');
$sitemap->generateSitemap();
$generator = \Drupal::service('simple_sitemap.generator');
$generator->generateSitemap();
}
}
......@@ -308,15 +308,15 @@ class Simplesitemap {
/**
* Generates and returns the sitemap index as string.
*
* @param array $sitemap
* @param array $chunks
* Sitemap chunks which to generate the index from.
*
* @return string
* The sitemap index.
*/
private function getSitemapIndex($sitemap) {
private function getSitemapIndex($chunks) {
$generator = new SitemapGenerator($this);
return $generator->generateSitemapIndex($sitemap);
return $generator->generateSitemapIndex($chunks);
}
/**
......@@ -354,10 +354,10 @@ class Simplesitemap {
* Formatted timestamp of last sitemap generation, otherwise FALSE.
*/
public function getGeneratedAgo() {
$sitemap = $this->fetchSitemap();
if (isset($sitemap[1]->sitemap_created)) {
$chunks = $this->fetchSitemap();
if (isset($chunks[1]->sitemap_created)) {
return \Drupal::service('date.formatter')
->formatInterval(REQUEST_TIME - $sitemap[1]->sitemap_created);
->formatInterval(REQUEST_TIME - $chunks[1]->sitemap_created);
}
return FALSE;
}
......
......@@ -20,12 +20,12 @@ class SitemapGenerator {
const XMLNS = 'http://www.sitemaps.org/schemas/sitemap/0.9';
const XMLNS_XHTML = 'http://www.w3.org/1999/xhtml';
private $sitemap;
private $generator;
private $links;
private $generateFrom;
function __construct($sitemap) {
$this->sitemap = $sitemap;
function __construct($generator) {
$this->generator = $generator;
$this->links = [];
$this->generateFrom = 'form';
}
......@@ -41,11 +41,11 @@ class SitemapGenerator {
$batch = new Batch();
$batch->setBatchInfo([
'from' => $this->generateFrom,
'batch_process_limit' => !empty($this->sitemap->getSetting('batch_process_limit'))
? $this->sitemap->getSetting('batch_process_limit') : NULL,
'max_links' => $this->sitemap->getSetting('max_links'),
'remove_duplicates' => $this->sitemap->getSetting('remove_duplicates'),
'entity_types' => $this->sitemap->getConfig('entity_types'),
'batch_process_limit' => !empty($this->generator->getSetting('batch_process_limit'))
? $this->generator->getSetting('batch_process_limit') : NULL,
'max_links' => $this->generator->getSetting('max_links'),
'remove_duplicates' => $this->generator->getSetting('remove_duplicates'),
'entity_types' => $this->generator->getConfig('entity_types'),
]);
$batch->addOperations('custom_paths', $this->batchAddCustomPaths());
$batch->addOperations('entity_types', $this->batchAddEntityTypePaths());
......@@ -59,7 +59,7 @@ class SitemapGenerator {
*/
private function batchAddCustomPaths() {
$link_generator = new CustomLinkGenerator();
return $link_generator->getCustomPaths($this->sitemap->getConfig('custom'));
return $link_generator->getCustomPaths($this->generator->getConfig('custom'));
}
/**
......@@ -71,7 +71,7 @@ class SitemapGenerator {
private function batchAddEntityTypePaths() {
$operations = [];
$sitemap_entity_types = Simplesitemap::getSitemapEntityTypes();
$entity_types = $this->sitemap->getConfig('entity_types');
$entity_types = $this->generator->getConfig('entity_types');
foreach($entity_types as $entity_type_name => $bundles) {
if (isset($sitemap_entity_types[$entity_type_name])) {
$keys = $sitemap_entity_types[$entity_type_name]->getKeys();
......@@ -119,12 +119,12 @@ class SitemapGenerator {
/**
* Generates and returns the sitemap index for all sitemap chunks.
*
* @param array $sitemap_chunks
* @param array $chunks
* All sitemap chunks keyed by the chunk ID.
*
* @return string sitemap index
*/
public function generateSitemapIndex($sitemap_chunks) {
public function generateSitemapIndex($chunks) {
$writer = new XMLWriter();
$writer->openMemory();
$writer->setIndent(TRUE);
......@@ -132,7 +132,7 @@ class SitemapGenerator {
$writer->startElement('sitemapindex');
$writer->writeAttribute('xmlns', self::XMLNS);
foreach ($sitemap_chunks as $chunk_id => $chunk_data) {
foreach ($chunks as $chunk_id => $chunk_data) {
$writer->startElement('sitemap');
$writer->writeElement('loc', $GLOBALS['base_url'] . '/sitemaps/'
. $chunk_id . '/' . 'sitemap.xml');
......@@ -147,12 +147,12 @@ class SitemapGenerator {
/**
* Generates and returns a sitemap chunk.
*
* @param array $sitemap_links
* @param array $links
* All links with their multilingual versions and settings.
*
* @return string sitemap chunk
*/
private static function generateSitemapChunk($sitemap_links) {
private static function generateSitemapChunk($links) {
$default_language_id = Simplesitemap::getDefaultLangId();
$writer = new XMLWriter();
......@@ -163,7 +163,7 @@ class SitemapGenerator {
$writer->writeAttribute('xmlns', self::XMLNS);
$writer->writeAttribute('xmlns:xhtml', self::XMLNS_XHTML);
foreach ($sitemap_links as $link) {
foreach ($links as $link) {
$writer->startElement('url');
// Adding url to standard language.
......
......@@ -48,11 +48,11 @@ class SimplesitemapTest extends WebTestBase {
$node = $this->createNode(['title' => 'Node 2', 'type' => 'page']);
// Set up the module.
$sitemap = \Drupal::service('simple_sitemap.generator');
$sitemap->setBundleSettings('node', 'page', ['index' => 1, 'priority' => '0.5']);
$generator = \Drupal::service('simple_sitemap.generator');
$generator->setBundleSettings('node', 'page', ['index' => 1, 'priority' => '0.5']);
// Verify the cache was flushed and node is in the sitemap.
$sitemap->generateSitemap('nobatch');
$generator->generateSitemap('nobatch');
$this->drupalGet('sitemap.xml');
$this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'MISS');
$this->assertText('node/' . $node->id());
......@@ -61,34 +61,34 @@ class SimplesitemapTest extends WebTestBase {
$this->assertText('node/' . $node->id());
// Test overriding of bundle entities.
$sitemap->setEntityInstanceSettings('node', $node->id(), ['index' => 1, 'priority' => '0.1']);
$sitemap->generateSitemap('nobatch');
$generator->setEntityInstanceSettings('node', $node->id(), ['index' => 1, 'priority' => '0.1']);
$generator->generateSitemap('nobatch');
$this->drupalGet('sitemap.xml');
$this->assertText('0.1');
// Test sitemap index.
$sitemap->saveSetting('max_links', 1);
$sitemap->generateSitemap('nobatch');
$generator->saveSetting('max_links', 1);
$generator->generateSitemap('nobatch');
$this->drupalGet('sitemap.xml');
$this->assertText('sitemaps/2/sitemap.xml');
$sitemap->saveSetting('max_links', 2000);
$generator->saveSetting('max_links', 2000);
// Test disabling sitemap support for an entity type.
$sitemap->disableEntityType('node');
$sitemap->generateSitemap('nobatch');
$generator->disableEntityType('node');
$generator->generateSitemap('nobatch');
$this->drupalGet('sitemap.xml');
$this->assertNoText('node/');
// Test adding a custom link to the sitemap.
$sitemap->addCustomLink('/node/' . $node->id(), ['priority' => '0.2']);
$sitemap->generateSitemap('nobatch');
$generator->addCustomLink('/node/' . $node->id(), ['priority' => '0.2']);
$generator->generateSitemap('nobatch');
$this->drupalGet('sitemap.xml');
$this->assertText('0.2');
// Test removing custom links from the sitemap.
$sitemap->removeCustomLink('/node/' . $node->id());
$sitemap->generateSitemap('nobatch');
$generator->removeCustomLink('/node/' . $node->id());
$generator->generateSitemap('nobatch');
$this->drupalGet('sitemap.xml');
$this->assertNoText('0.2');
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment