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() { ...@@ -22,6 +22,6 @@ function simple_sitemap_drush_command() {
* Regenerate sitemap for all languages. * Regenerate sitemap for all languages.
*/ */
function drush_simple_sitemap_generate() { function drush_simple_sitemap_generate() {
$sitemap = \Drupal::service('simple_sitemap.generator'); $generator = \Drupal::service('simple_sitemap.generator');
$sitemap->generateSitemap('drush'); $generator->generateSitemap('drush');
} }
...@@ -21,8 +21,8 @@ function simple_sitemap_requirements($phase) { ...@@ -21,8 +21,8 @@ function simple_sitemap_requirements($phase) {
switch($phase) { switch($phase) {
case 'runtime': case 'runtime':
$sitemap = \Drupal::service('simple_sitemap.generator'); $generator = \Drupal::service('simple_sitemap.generator');
$generated_ago = $sitemap->getGeneratedAgo(); $generated_ago = $generator->getGeneratedAgo();
if (!$generated_ago) { if (!$generated_ago) {
$value = t('Not available'); $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']); $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() { ...@@ -79,8 +79,8 @@ function simple_sitemap_schema() {
* Implements hook_install(). * Implements hook_install().
*/ */
function simple_sitemap_install() { function simple_sitemap_install() {
$sitemap = \Drupal::service('simple_sitemap.generator'); $generator = \Drupal::service('simple_sitemap.generator');
$sitemap->generateSitemap('nobatch'); $generator->generateSitemap('nobatch');
$base_url = $GLOBALS['base_url']; $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"])); 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) { ...@@ -67,25 +67,25 @@ function simple_sitemap_entity_form_submit($form, &$form_state) {
// Only make changes in DB if sitemap settings actually changed. // Only make changes in DB if sitemap settings actually changed.
if (Form::valuesChanged($form, $values)) { if (Form::valuesChanged($form, $values)) {
$sitemap = \Drupal::service('simple_sitemap.generator'); $generator = \Drupal::service('simple_sitemap.generator');
$f = new Form($form_state); $f = new Form($form_state);
switch ($f->entityCategory) { switch ($f->entityCategory) {
case 'bundle': case 'bundle':
$f->bundleName = !empty($f->bundleName) ? $f->bundleName : $f->getFormEntityId(); $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; break;
case 'instance': case 'instance':
$f->instanceId = !empty($f->instanceId) ? $f->instanceId : $f->getFormEntityId(); $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; break;
} }
// Regenerate sitemaps according to user setting. // Regenerate sitemaps according to user setting.
if ($values['simple_sitemap_regenerate_now']) { if ($values['simple_sitemap_regenerate_now']) {
$sitemap->generateSitemap(); $generator->generateSitemap();
} }
} }
} }
...@@ -94,9 +94,9 @@ function simple_sitemap_entity_form_submit($form, &$form_state) { ...@@ -94,9 +94,9 @@ function simple_sitemap_entity_form_submit($form, &$form_state) {
* Implements hook_cron. * Implements hook_cron.
*/ */
function simple_sitemap_cron() { function simple_sitemap_cron() {
$sitemap = \Drupal::service('simple_sitemap.generator'); $generator = \Drupal::service('simple_sitemap.generator');
if ($sitemap->getSetting('cron_generate')) { if ($generator->getSetting('cron_generate')) {
$sitemap->generateSitemap('backend'); $generator->generateSitemap('backend');
} }
} }
...@@ -108,13 +108,13 @@ function simple_sitemap_cron() { ...@@ -108,13 +108,13 @@ function simple_sitemap_cron() {
* @todo Not working for menu bundles, as they are technically not bundles. Implement hook_menu_delete(). * @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) { function simple_sitemap_entity_bundle_delete($entity_type_id, $bundle) {
$sitemap = \Drupal::service('simple_sitemap.generator'); $generator = \Drupal::service('simple_sitemap.generator');
$entity_types = $sitemap->getConfig('entity_types'); $entity_types = $generator->getConfig('entity_types');
if (isset($entity_types[$entity_type_id][$bundle])) { if (isset($entity_types[$entity_type_id][$bundle])) {
unset($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']); $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.'); $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. // 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) { ...@@ -127,14 +127,14 @@ function simple_sitemap_entity_bundle_delete($entity_type_id, $bundle) {
* Removes settings of the removed entity. * Removes settings of the removed entity.
*/ */
function simple_sitemap_entity_delete(Drupal\Core\Entity\EntityInterface $entity) { function simple_sitemap_entity_delete(Drupal\Core\Entity\EntityInterface $entity) {
$sitemap = \Drupal::service('simple_sitemap.generator'); $generator = \Drupal::service('simple_sitemap.generator');
$entity_types = $sitemap->getConfig('entity_types'); $entity_types = $generator->getConfig('entity_types');
$entity_type_id = $entity->getEntityTypeId(); $entity_type_id = $entity->getEntityTypeId();
$bundle_name = !empty($entity->bundle()) ? $entity->bundle() : $entity_type_id; $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. $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()])) { if (isset($entity_types[$entity_type_id][$bundle_name]['entities'][$entity->id()])) {
unset($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 { ...@@ -21,30 +21,30 @@ class SimplesitemapController extends ControllerBase {
* *
* @var \Drupal\simple_sitemap\Simplesitemap * @var \Drupal\simple_sitemap\Simplesitemap
*/ */
protected $sitemapGenerator; protected $generator;
/** /**
* SimplesitemapController constructor. * SimplesitemapController constructor.
* *
* @param \Drupal\simple_sitemap\Simplesitemap $sitemap_generator * @param \Drupal\simple_sitemap\Simplesitemap $generator
* The sitemap generator. * The sitemap generator.
*/ */
public function __construct($sitemap_generator) { public function __construct($generator) {
$this->sitemapGenerator = $sitemap_generator; $this->generator = $generator;
} }
/** /**
* Returns the whole sitemap, a requested sitemap chunk, or the sitemap index file. * 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 * Optional ID of the sitemap chunk. If none provided, the first chunk or
* the sitemap index is fetched. * the sitemap index is fetched.
* *
* @return object Response * @return object Response
* Returns an XML response. * Returns an XML response.
*/ */
public function getSitemap($sitemap_id = NULL) { public function getSitemap($chunk_id = NULL) {
$output = $this->sitemapGenerator->getSitemap($sitemap_id); $output = $this->generator->getSitemap($chunk_id);
$output = !$output ? '' : $output; $output = !$output ? '' : $output;
// Display sitemap with correct xml header. // Display sitemap with correct xml header.
...@@ -60,5 +60,4 @@ class SimplesitemapController extends ControllerBase { ...@@ -60,5 +60,4 @@ class SimplesitemapController extends ControllerBase {
public static function create(ContainerInterface $container) { public static function create(ContainerInterface $container) {
return new static($container->get('simple_sitemap.generator')); return new static($container->get('simple_sitemap.generator'));
} }
} }
...@@ -22,7 +22,7 @@ class Form { ...@@ -22,7 +22,7 @@ class Form {
public $instanceId; public $instanceId;
private $formState; private $formState;
private $sitemap; private $generator;
private static $allowedFormOperations = ['default', 'edit', 'add']; private static $allowedFormOperations = ['default', 'edit', 'add'];
private static $valuesToCheck = ['simple_sitemap_index_content', 'simple_sitemap_priority', 'simple_sitemap_regenerate_now']; private static $valuesToCheck = ['simple_sitemap_index_content', 'simple_sitemap_priority', 'simple_sitemap_regenerate_now'];
...@@ -40,7 +40,7 @@ class Form { ...@@ -40,7 +40,7 @@ class Form {
$this->formState = $form_state; $this->formState = $form_state;
$this->entityCategory = NULL; $this->entityCategory = NULL;
$this->alteringForm = TRUE; $this->alteringForm = TRUE;
$this->sitemap = \Drupal::service('simple_sitemap.generator'); $this->generator = \Drupal::service('simple_sitemap.generator');
$this->getEntityData(); $this->getEntityData();
} }
...@@ -54,12 +54,12 @@ class Form { ...@@ -54,12 +54,12 @@ class Form {
$this->alteringForm = FALSE; $this->alteringForm = FALSE;
// Do not alter the form if entity is not enabled in sitemap settings. // 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; $this->alteringForm = FALSE;
// Do not alter the form, if sitemap is disabled for the entity type of this entity instance. // Do not alter the form, if sitemap is disabled for the entity type of this entity instance.
elseif ($this->entityCategory == 'instance' elseif ($this->entityCategory == 'instance'
&& !$this->sitemap->bundleIsIndexed($this->entityTypeId, $this->bundleName)) && !$this->generator->bundleIsIndexed($this->entityTypeId, $this->bundleName))
$this->alteringForm = FALSE; $this->alteringForm = FALSE;
} }
...@@ -86,7 +86,7 @@ class Form { ...@@ -86,7 +86,7 @@ class Form {
'#description' => t('This setting will regenerate the whole sitemap including the above changes.'), '#description' => t('This setting will regenerate the whole sitemap including the above changes.'),
'#default_value' => FALSE, '#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.'); $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 { ...@@ -95,11 +95,11 @@ class Form {
$prefix = $multiple ? $this->entityTypeId . '_' : ''; $prefix = $multiple ? $this->entityTypeId . '_' : '';
if ($this->entityCategory == 'instance') { if ($this->entityCategory == 'instance') {
$bundle_settings = $this->sitemap->getBundleSettings($this->entityTypeId, $this->bundleName); $bundle_settings = $this->generator->getBundleSettings($this->entityTypeId, $this->bundleName);
$settings = !is_null($this->instanceId) ? $this->sitemap->getEntityInstanceSettings($this->entityTypeId, $this->instanceId) : $bundle_settings; $settings = !is_null($this->instanceId) ? $this->generator->getEntityInstanceSettings($this->entityTypeId, $this->instanceId) : $bundle_settings;
} }
else { else {
$settings = $this->sitemap->getBundleSettings($this->entityTypeId, $this->bundleName); $settings = $this->generator->getBundleSettings($this->entityTypeId, $this->bundleName);
} }
$index = isset($settings['index']) ? $settings['index'] : 0; $index = isset($settings['index']) ? $settings['index'] : 0;
$priority = isset($settings['priority']) ? $settings['priority'] : self::PRIORITY_DEFAULT; $priority = isset($settings['priority']) ? $settings['priority'] : self::PRIORITY_DEFAULT;
......
...@@ -35,9 +35,9 @@ class SimplesitemapCustomLinksForm extends ConfigFormBase { ...@@ -35,9 +35,9 @@ class SimplesitemapCustomLinksForm extends ConfigFormBase {
*/ */
public function buildForm(array $form, FormStateInterface $form_state) { public function buildForm(array $form, FormStateInterface $form_state) {
$sitemap = \Drupal::service('simple_sitemap.generator'); $generator = \Drupal::service('simple_sitemap.generator');
$setting_string = ''; $setting_string = '';
foreach ($sitemap->getConfig('custom') as $custom_link) { foreach ($generator->getConfig('custom') as $custom_link) {
$setting_string .= isset($custom_link['priority']) $setting_string .= isset($custom_link['priority'])
? $custom_link['path'] . ' ' . Form::formatPriority($custom_link['priority']) ? $custom_link['path'] . ' ' . Form::formatPriority($custom_link['priority'])
: $custom_link['path']; : $custom_link['path'];
...@@ -90,17 +90,17 @@ class SimplesitemapCustomLinksForm extends ConfigFormBase { ...@@ -90,17 +90,17 @@ class SimplesitemapCustomLinksForm extends ConfigFormBase {
* {@inheritdoc} * {@inheritdoc}
*/ */
public function submitForm(array &$form, FormStateInterface $form_state) { 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')); $custom_link_config = $this->getCustomLinkConfig($form_state->getValue('custom_links'));
$sitemap->removeCustomLinks(); $generator->removeCustomLinks();
foreach ($custom_link_config as $link_config) { 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); parent::submitForm($form, $form_state);
// Regenerate sitemaps according to user setting. // Regenerate sitemaps according to user setting.
if ($form_state->getValue('simple_sitemap_regenerate_now')) { if ($form_state->getValue('simple_sitemap_regenerate_now')) {
$sitemap->generateSitemap(); $generator->generateSitemap();
} }
} }
......
...@@ -36,7 +36,7 @@ class SimplesitemapEntitiesForm extends ConfigFormBase { ...@@ -36,7 +36,7 @@ class SimplesitemapEntitiesForm extends ConfigFormBase {
*/ */
public function buildForm(array $form, FormStateInterface $form_state) { 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'] = [ $form['simple_sitemap_entities']['entities'] = [
'#title' => t('Sitemap entities'), '#title' => t('Sitemap entities'),
...@@ -59,13 +59,13 @@ class SimplesitemapEntitiesForm extends ConfigFormBase { ...@@ -59,13 +59,13 @@ class SimplesitemapEntitiesForm extends ConfigFormBase {
$form['simple_sitemap_entities']['entities'][$entity_type_id] = [ $form['simple_sitemap_entities']['entities'][$entity_type_id] = [
'#type' => 'details', '#type' => 'details',
'#title' => $entity_type_label, '#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'] = [ $form['simple_sitemap_entities']['entities'][$entity_type_id][$entity_type_id . '_enabled'] = [
'#type' => 'checkbox', '#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]), '#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.'), '#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); $form['#attached']['drupalSettings']['simple_sitemap']['all_entities'][] = str_replace('_', '-', $entity_type_id);
if (Simplesitemap::entityTypeIsAtomic($entity_type_id)) { if (Simplesitemap::entityTypeIsAtomic($entity_type_id)) {
...@@ -85,29 +85,29 @@ class SimplesitemapEntitiesForm extends ConfigFormBase { ...@@ -85,29 +85,29 @@ class SimplesitemapEntitiesForm extends ConfigFormBase {
* {@inheritdoc} * {@inheritdoc}
*/ */
public function submitForm(array &$form, FormStateInterface $form_state) { public function submitForm(array &$form, FormStateInterface $form_state) {
$sitemap = \Drupal::service('simple_sitemap.generator'); $generator = \Drupal::service('simple_sitemap.generator');
$values = $form_state->getValues(); $values = $form_state->getValues();
foreach($values as $field_name => $value) { foreach($values as $field_name => $value) {
if (substr($field_name, -strlen('_enabled')) == '_enabled') { if (substr($field_name, -strlen('_enabled')) == '_enabled') {
$entity_type_id = substr($field_name, 0, -8); $entity_type_id = substr($field_name, 0, -8);
if ($value) { if ($value) {
$sitemap->enableEntityType($entity_type_id); $generator->enableEntityType($entity_type_id);
if (Simplesitemap::entityTypeIsAtomic($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, 'index' => TRUE,
'priority' => $values[$entity_type_id . '_simple_sitemap_priority'] 'priority' => $values[$entity_type_id . '_simple_sitemap_priority']
]); ]);
} }
} }
else else
$sitemap->disableEntityType($entity_type_id); $generator->disableEntityType($entity_type_id);
} }
} }
parent::submitForm($form, $form_state); parent::submitForm($form, $form_state);
// Regenerate sitemaps according to user setting. // Regenerate sitemaps according to user setting.
if ($form_state->getValue('simple_sitemap_regenerate_now')) { if ($form_state->getValue('simple_sitemap_regenerate_now')) {
$sitemap->generateSitemap(); $generator->generateSitemap();
} }
} }
} }
...@@ -34,7 +34,7 @@ class SimplesitemapSettingsForm extends ConfigFormBase { ...@@ -34,7 +34,7 @@ class SimplesitemapSettingsForm extends ConfigFormBase {
*/ */
public function buildForm(array $form, FormStateInterface $form_state) { 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>"; $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 { ...@@ -60,7 +60,7 @@ class SimplesitemapSettingsForm extends ConfigFormBase {
'#type' => 'checkbox', '#type' => 'checkbox',
'#title' => t('Regenerate the sitemap on every cron run'), '#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.'), '#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'] = [ $form['simple_sitemap_settings']['advanced'] = [
...@@ -72,7 +72,7 @@ class SimplesitemapSettingsForm extends ConfigFormBase { ...@@ -72,7 +72,7 @@ class SimplesitemapSettingsForm extends ConfigFormBase {
'#type' => 'checkbox', '#type' => 'checkbox',
'#title' => t('Exclude duplicate links'), '#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).'), '#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'] = [ $form['simple_sitemap_settings']['advanced']['max_links'] = [
...@@ -81,7 +81,7 @@ class SimplesitemapSettingsForm extends ConfigFormBase { ...@@ -81,7 +81,7 @@ class SimplesitemapSettingsForm extends ConfigFormBase {
'#type' => 'textfield', '#type' => 'textfield',
'#maxlength' => 5, '#maxlength' => 5,
'#size' => 5, '#size' => 5,
'#default_value' => $sitemap->getSetting('max_links'), '#default_value' => $generator->getSetting('max_links'),
]; ];
$form['simple_sitemap_settings']['advanced']['batch_process_limit'] = [ $form['simple_sitemap_settings']['advanced']['batch_process_limit'] = [
...@@ -90,7 +90,7 @@ class SimplesitemapSettingsForm extends ConfigFormBase { ...@@ -90,7 +90,7 @@ class SimplesitemapSettingsForm extends ConfigFormBase {
'#type' => 'textfield', '#type' => 'textfield',
'#maxlength' => 5, '#maxlength' => 5,
'#size' => 5, '#size' => 5,
'#default_value' => $sitemap->getSetting('batch_process_limit'), '#default_value' => $generator->getSetting('batch_process_limit'),
]; ];
return parent::buildForm($form, $form_state); return parent::buildForm($form, $form_state);
...@@ -117,16 +117,16 @@ class SimplesitemapSettingsForm extends ConfigFormBase { ...@@ -117,16 +117,16 @@ class SimplesitemapSettingsForm extends ConfigFormBase {
* {@inheritdoc} * {@inheritdoc}
*/ */
public function submitForm(array &$form, FormStateInterface $form_state) { public function submitForm(array &$form, FormStateInterface $form_state) {
$sitemap = \Drupal::service('simple_sitemap.generator'); $generator = \Drupal::service('simple_sitemap.generator');
$sitemap->saveSetting('max_links', $form_state->getValue('max_links')); $generator->saveSetting('max_links', $form_state->getValue('max_links'));
$sitemap->saveSetting('cron_generate', $form_state->getValue('cron_generate')); $generator->saveSetting('cron_generate', $form_state->getValue('cron_generate'));
$sitemap->saveSetting('remove_duplicates', $form_state->getValue('remove_duplicates')); $generator->saveSetting('remove_duplicates', $form_state->getValue('remove_duplicates'));
$sitemap->saveSetting('batch_process_limit', $form_state->getValue('batch_process_limit')); $generator->saveSetting('batch_process_limit', $form_state->getValue('batch_process_limit'));
parent::submitForm($form, $form_state); parent::submitForm($form, $form_state);
} }
public function generateSitemap(array &$form, FormStateInterface $form_state) { public function generateSitemap(array &$form, FormStateInterface $form_state) {
$sitemap = \Drupal::service('simple_sitemap.generator'); $generator = \Drupal::service('simple_sitemap.generator');
$sitemap->generateSitemap(); $generator->generateSitemap();
} }
} }
...@@ -308,15 +308,15 @@ class Simplesitemap { ...@@ -308,15 +308,15 @@ class Simplesitemap {
/** /**
* Generates and returns the sitemap index as string. * Generates and returns the sitemap index as string.
* *
* @param array $sitemap * @param array $chunks
* Sitemap chunks which to generate the index from. * Sitemap chunks which to generate the index from.
* *
* @return string * @return string
* The sitemap index. * The sitemap index.
*/ */
private function getSitemapIndex($sitemap) { private function getSitemapIndex($chunks) {
$generator = new SitemapGenerator($this); $generator = new SitemapGenerator($this);
return $generator->generateSitemapIndex($sitemap); return $generator->generateSitemapIndex($chunks);
} }
/** /**
...@@ -354,10 +354,10 @@ class Simplesitemap { ...@@ -354,10 +354,10 @@ class Simplesitemap {
* Formatted timestamp of last sitemap generation, otherwise FALSE. * Formatted timestamp of last sitemap generation, otherwise FALSE.
*/ */
public function getGeneratedAgo() { public function getGeneratedAgo() {
$sitemap = $this->fetchSitemap(); $chunks = $this->fetchSitemap();
if (isset($sitemap[1]->sitemap_created)) { if (isset($chunks[1]->sitemap_created)) {
return \Drupal::service('date.formatter') return \Drupal::service('date.formatter')
->formatInterval(REQUEST_TIME - $sitemap[1]->sitemap_created); ->formatInterval(REQUEST_TIME - $chunks[1]->sitemap_created);
} }
return FALSE; return FALSE;
} }
......
...@@ -20,12 +20,12 @@ class SitemapGenerator { ...@@ -20,12 +20,12 @@ class SitemapGenerator {
const XMLNS = 'http://www.sitemaps.org/schemas/sitemap/0.9'; const XMLNS = 'http://www.sitemaps.org/schemas/sitemap/0.9';
const XMLNS_XHTML = 'http://www.w3.org/1999/xhtml'; const XMLNS_XHTML = 'http://www.w3.org/1999/xhtml';
private $sitemap; private $generator;
private $links; private $links;
private $generateFrom; private $generateFrom;
function __construct($sitemap) { function __construct($generator) {
$this->sitemap = $sitemap; $this->generator = $generator;
$this->links = []; $this->links = [];
$this->generateFrom = 'form'; $this->generateFrom = 'form';
} }
...@@ -41,11 +41,11 @@ class SitemapGenerator { ...@@ -41,11 +41,11 @@ class SitemapGenerator {
$batch = new Batch(); $batch = new Batch();
$batch->setBatchInfo([ $batch->setBatchInfo([
'from' => $this->generateFrom, 'from' => $this->generateFrom,
'batch_process_limit' => !empty($this->sitemap->getSetting('batch_process_limit')) 'batch_process_limit' => !empty($this->generator->getSetting('batch_process_limit'))
? $this->sitemap->getSetting('batch_process_limit') : NULL, ? $this->generator->getSetting('batch_process_limit') : NULL,
'max_links' => $this->sitemap->getSetting('max_links'), 'max_links' => $this->generator->getSetting('max_links'),
'remove_duplicates' => $this->sitemap->getSetting('remove_duplicates'), 'remove_duplicates' => $this->generator->getSetting('remove_duplicates'),
'entity_types' => $this->sitemap->getConfig('entity_types'), 'entity_types' => $this->generator->getConfig('entity_types'),
]); ]);
$batch->addOperations('custom_paths', $this->batchAddCustomPaths()); $batch->addOperations('custom_paths', $this->batchAddCustomPaths());
$batch->addOperations('entity_types', $this->batchAddEntityTypePaths()); $batch->addOperations('entity_types', $this->batchAddEntityTypePaths());
...@@ -59,7 +59,7 @@ class SitemapGenerator { ...@@ -59,7 +59,7 @@ class SitemapGenerator {
*/ */
private function batchAddCustomPaths() { private function batchAddCustomPaths() {
$link_generator = new CustomLinkGenerator(); $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 { ...@@ -71,7 +71,7 @@ class SitemapGenerator {
private function batchAddEntityTypePaths() { private function batchAddEntityTypePaths() {
$operations = []; $operations = [];
$sitemap_entity_types = Simplesitemap::getSitemapEntityTypes(); $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) { foreach($entity_types as $entity_type_name => $bundles) {
if (isset($sitemap_entity_types[$entity_type_name])) { if (isset($sitemap_entity_types[$entity_type_name])) {
$keys = $sitemap_entity_types[$entity_type_name]->getKeys(); $keys = $sitemap_entity_types[$entity_type_name]->getKeys();
...@@ -119,12 +119,12 @@ class SitemapGenerator { ...@@ -119,12 +119,12 @@ class SitemapGenerator {
/** /**
* Generates and returns the sitemap index for all sitemap chunks. * 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. * All sitemap chunks keyed by the chunk ID.
* *
* @return string sitemap index * @return string sitemap index
*/ */
public function generateSitemapIndex($sitemap_chunks) { public function generateSitemapIndex($chunks) {
$writer = new XMLWriter(); $writer = new XMLWriter();
$writer->openMemory(); $writer->openMemory();
$writer->setIndent(TRUE); $writer->setIndent(TRUE);
...@@ -132,7 +132,7 @@ class SitemapGenerator { ...@@ -132,7 +132,7 @@ class SitemapGenerator {
$writer->startElement('sitemapindex'); $writer->startElement('sitemapindex');
$writer->writeAttribute('xmlns', self::XMLNS); $writer->writeAttribute('xmlns', self::XMLNS);
foreach ($sitemap_chunks as $chunk_id => $chunk_data) { foreach ($chunks as $chunk_id => $chunk_data) {
$writer->startElement('sitemap'); $writer->startElement('sitemap');
$writer->writeElement('loc', $GLOBALS['base_url'] . '/sitemaps/' $writer->writeElement('loc', $GLOBALS['base_url'] . '/sitemaps/'
. $chunk_id . '/' . 'sitemap.xml'); . $chunk_id . '/' . 'sitemap.xml');
...@@ -147,12 +147,12 @@ class SitemapGenerator { ...@@ -147,12 +147,12 @@ class SitemapGenerator {
/** /**
* Generates and returns a sitemap chunk. * Generates and returns a sitemap chunk.
* *
* @param array $sitemap_links * @param array $links
* All links with their multilingual versions and settings. * All links with their multilingual versions and settings.
* *
* @return string sitemap chunk * @return string sitemap chunk
*/ */
private static function generateSitemapChunk($sitemap_links) { private static function generateSitemapChunk($links) {
$default_language_id = Simplesitemap::getDefaultLangId(); $default_language_id = Simplesitemap::getDefaultLangId();
$writer = new XMLWriter(); $writer = new XMLWriter();
...@@ -163,7 +163,7 @@ class SitemapGenerator { ...@@ -163,7 +163,7 @@ class SitemapGenerator {
$writer->writeAttribute('xmlns', self::XMLNS); $writer->writeAttribute('xmlns', self::XMLNS);
$writer->writeAttribute('xmlns:xhtml', self::XMLNS_XHTML);