Commit 1c2cdead authored by Pawel G's avatar Pawel G

Clean up some

parent 067530c4
...@@ -110,9 +110,16 @@ Altering sitemap attributes and sitemap index attributes is possible through the ...@@ -110,9 +110,16 @@ Altering sitemap attributes and sitemap index attributes is possible through the
use of hook_simple_sitemap_attributes_alter(&$attributes){} and use of hook_simple_sitemap_attributes_alter(&$attributes){} and
hook_simple_sitemap_index_attributes_alter(&$index_attributes){}. hook_simple_sitemap_index_attributes_alter(&$index_attributes){}.
Adding new URL generator plugins and altering existing ones is possible through Altering URL generator plugins is possible through
the use of hook_simple_sitemap_url_generators_alter(&$generators){}. the use of hook_simple_sitemap_url_generators_alter(&$generators){}.
In case this module's URL generators do not cover your use case, it is possible
to implement new generator plugins in a custom module. To do it, simply extend
the Drupal\simple_sitemap\Plugin\simple_sitemap\UrlGenerator\UrlGeneratorBase
class. See the generator plugins included in this module and check the API docs
(https://www.drupal.org/docs/8/api/plugin-api/plugin-api-overview) to learn how
to implement plugins.
There are API methods for altering stored inclusion settings, status queries and There are API methods for altering stored inclusion settings, status queries and
programmatic sitemap generation. These include: programmatic sitemap generation. These include:
......
...@@ -18,7 +18,7 @@ function simple_sitemap_requirements($phase) { ...@@ -18,7 +18,7 @@ function simple_sitemap_requirements($phase) {
$requirements['simple_sitemap_php_extensions'] = [ $requirements['simple_sitemap_php_extensions'] = [
'title' => t('Simple XML sitemap PHP extensions'), 'title' => t('Simple XML sitemap PHP extensions'),
'value' => t('Missing PHP xmlwriter extension'), 'value' => t('Missing PHP xmlwriter extension'),
'description' => t("In order to be able to generate sitemaps, the Simple XML sitemap module requires the <em>xmlwriter</em> PHP extension to be enabled."), 'description' => t('In order to be able to generate sitemaps, the Simple XML sitemap module requires the <em>xmlwriter</em> PHP extension to be enabled.'),
'severity' => REQUIREMENT_ERROR, 'severity' => REQUIREMENT_ERROR,
]; ];
} }
...@@ -34,8 +34,8 @@ function simple_sitemap_requirements($phase) { ...@@ -34,8 +34,8 @@ function simple_sitemap_requirements($phase) {
if (!$generated_ago) { if (!$generated_ago) {
$value = t('Not available'); $value = t('Not available');
$description = t($cron_generation $description = t($cron_generation
? "Run cron, or <a href='@generate'>generate</a> the sitemap manually." ? 'Run cron, or <a href="@generate">generate</a> the sitemap manually.'
: "Generation on cron run is disabled. <a href='@generate'>Generate</a> the sitemap manually.", [ : 'Generation on cron run is disabled. <a href="@generate">Generate</a> the sitemap manually.', [
'@generate' => $GLOBALS['base_url'] . '/admin/config/search/simplesitemap' '@generate' => $GLOBALS['base_url'] . '/admin/config/search/simplesitemap'
] ]
); );
...@@ -43,10 +43,10 @@ function simple_sitemap_requirements($phase) { ...@@ -43,10 +43,10 @@ function simple_sitemap_requirements($phase) {
} }
else { else {
$value = t('XML sitemap is available'); $value = t('XML sitemap is available');
$description = t("The <a href='@sitemap'>XML sitemap</a> was generated @ago ago." $description = t('The <a href="@sitemap">XML sitemap</a> was generated @ago ago.'
. ' ' . ($cron_generation . ' ' . ($cron_generation
? "Run cron, or <a href='@generate'>regenerate</a> the sitemap manually." ? 'Run cron, or <a href="@generate">regenerate</a> the sitemap manually.'
: "Generation on cron run is disabled. <a href='@generate'>Regenerate</a> the sitemap manually."), [ : 'Generation on cron run is disabled. <a href="@generate">Regenerate</a> the sitemap manually.'), [
'@sitemap' => $GLOBALS['base_url'] . '/sitemap.xml', '@sitemap' => $GLOBALS['base_url'] . '/sitemap.xml',
'@ago' => $generated_ago, '@ago' => $generated_ago,
'@generate' => $GLOBALS['base_url'] . '/admin/config/search/simplesitemap' '@generate' => $GLOBALS['base_url'] . '/admin/config/search/simplesitemap'
...@@ -307,7 +307,7 @@ function simple_sitemap_update_8206() { ...@@ -307,7 +307,7 @@ function simple_sitemap_update_8206() {
unset($custom_links[$i]); unset($custom_links[$i]);
} }
} }
\Drupal::service('config.factory')->getEditable("simple_sitemap.custom") \Drupal::service('config.factory')->getEditable('simple_sitemap.custom')
->setData(['links' => $custom_links])->save(); ->setData(['links' => $custom_links])->save();
} }
......
...@@ -46,12 +46,12 @@ function simple_sitemap_form_alter(&$form, FormStateInterface $form_state, $form ...@@ -46,12 +46,12 @@ function simple_sitemap_form_alter(&$form, FormStateInterface $form_state, $form
'#type' => 'details', '#type' => 'details',
'#group' => isset($form['additional_settings']) ? 'additional_settings' : 'advanced', '#group' => isset($form['additional_settings']) ? 'additional_settings' : 'advanced',
'#title' => t('Simple XML sitemap'), '#title' => t('Simple XML sitemap'),
'#description' => $f->getEntityCategory() == 'instance' ? t('Settings for this entity can be overridden here.') : '', '#description' => $f->getEntityCategory() === 'instance' ? t('Settings for this entity can be overridden here.') : '',
]; ];
// Attach some js magic to forms. // Attach some js magic to forms.
// todo: JS not working on comment entity form, hence disabling. // todo: JS not working on comment entity form, hence disabling.
if ($f->getEntityTypeId() != 'comment' || $f->getEntityCategory() != 'instance') { if ($f->getEntityTypeId() !== 'comment' || $f->getEntityCategory() !== 'instance') {
$form['#attached']['library'][] = 'simple_sitemap/form'; $form['#attached']['library'][] = 'simple_sitemap/form';
} }
...@@ -67,7 +67,7 @@ function simple_sitemap_form_alter(&$form, FormStateInterface $form_state, $form ...@@ -67,7 +67,7 @@ function simple_sitemap_form_alter(&$form, FormStateInterface $form_state, $form
// Add submission handler. // Add submission handler.
if (isset($form['actions']['submit']['#submit'])) { if (isset($form['actions']['submit']['#submit'])) {
foreach (array_keys($form['actions']) as $action) { foreach (array_keys($form['actions']) as $action) {
if ($action != 'preview' if ($action !== 'preview'
&& isset($form['actions'][$action]['#type']) && isset($form['actions'][$action]['#type'])
&& $form['actions'][$action]['#type'] === 'submit') { && $form['actions'][$action]['#type'] === 'submit') {
$form['actions'][$action]['#submit'][] = 'simple_sitemap_entity_form_submit'; $form['actions'][$action]['#submit'][] = 'simple_sitemap_entity_form_submit';
...@@ -240,7 +240,7 @@ function simple_sitemap_delete_bundle_config($entity_type_id, $bundle) { ...@@ -240,7 +240,7 @@ function simple_sitemap_delete_bundle_config($entity_type_id, $bundle) {
// Delete bundle settings. // Delete bundle settings.
\Drupal::service('config.factory')->getEditable("simple_sitemap.bundle_settings.$entity_type_id.$bundle")->delete(); \Drupal::service('config.factory')->getEditable("simple_sitemap.bundle_settings.$entity_type_id.$bundle")->delete();
$message = "You may want to <a href='@url'>regenerate</a> your XML sitemap now."; $message = 'You may want to <a href="@url">regenerate</a> your XML sitemap now.';
if ($generator->getSetting('cron_generate')) { if ($generator->getSetting('cron_generate')) {
$message .= ' Otherwise the sitemap will be regenerated during a future cron run.'; $message .= ' Otherwise the sitemap will be regenerated during a future cron run.';
} }
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
namespace Drupal\simple_sitemap; namespace Drupal\simple_sitemap;
use Drupal\Core\Entity\ContentEntityTypeInterface; use Drupal\Core\Entity\ContentEntityTypeInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Database\Connection; use Drupal\Core\Database\Connection;
use Drupal\Core\Entity\Entity; use Drupal\Core\Entity\Entity;
...@@ -37,10 +38,10 @@ class EntityHelper { ...@@ -37,10 +38,10 @@ class EntityHelper {
/** /**
* Gets an entity's bundle name. * Gets an entity's bundle name.
* *
* @param \Drupal\Core\Entity\Entity $entity * @param \Drupal\Core\Entity\EntityInterface $entity
* @return string * @return string
*/ */
public function getEntityInstanceBundleName(Entity $entity) { public function getEntityInstanceBundleName(EntityInterface $entity) {
return $entity->getEntityTypeId() == 'menu_link_content' return $entity->getEntityTypeId() == 'menu_link_content'
// Menu fix. // Menu fix.
? $entity->getMenuName() : $entity->bundle(); ? $entity->getMenuName() : $entity->bundle();
...@@ -49,10 +50,10 @@ class EntityHelper { ...@@ -49,10 +50,10 @@ class EntityHelper {
/** /**
* Gets the entity type id for a bundle. * Gets the entity type id for a bundle.
* *
* @param \Drupal\Core\Entity\Entity $entity * @param \Drupal\Core\Entity\EntityInterface $entity
* @return null|string * @return null|string
*/ */
public function getBundleEntityTypeId(Entity $entity) { public function getBundleEntityTypeId(EntityInterface $entity) {
return $entity->getEntityTypeId() == 'menu' return $entity->getEntityTypeId() == 'menu'
// Menu fix. // Menu fix.
? 'menu_link_content' : $entity->getEntityType()->getBundleOf(); ? 'menu_link_content' : $entity->getEntityType()->getBundleOf();
......
...@@ -230,38 +230,45 @@ class FormHelper { ...@@ -230,38 +230,45 @@ class FormHelper {
if ($this->getEntityCategory() === 'instance') { if ($this->getEntityCategory() === 'instance') {
$bundle_settings = $this->generator->getBundleSettings($this->getEntityTypeId(), $this->getBundleName()); $bundle_settings = $this->generator->getBundleSettings($this->getEntityTypeId(), $this->getBundleName());
$settings = NULL !== $this->getInstanceId() ? $this->generator->getEntityInstanceSettings($this->getEntityTypeId(), $this->getInstanceId()) : $bundle_settings; $settings = NULL !== $this->getInstanceId()
? $this->generator->getEntityInstanceSettings($this->getEntityTypeId(), $this->getInstanceId())
: $bundle_settings;
} }
else { else {
$settings = $this->generator->getBundleSettings($this->getEntityTypeId(), $this->getBundleName()); $settings = $this->generator->getBundleSettings($this->getEntityTypeId(), $this->getBundleName());
} }
$index = isset($settings['index']) ? $settings['index'] : 0; Simplesitemap::supplementDefaultSettings('entity', $settings, ['index' => 0]);
$priority = isset($settings['priority']) ? $settings['priority'] : self::PRIORITY_DEFAULT;
$changefreq = !empty($settings['changefreq']) ? $settings['changefreq'] : '';
$include_images = !empty($settings['include_images']) ? $settings['include_images'] : 0;
$bundle_name = !empty($this->getBundleName()) ? $this->getBundleName() : $this->t('undefined'); $bundle_name = !empty($this->getBundleName()) ? $this->getBundleName() : $this->t('undefined');
// Index
if (!$multiple) { if (!$multiple) {
$form_fragment[$prefix . 'simple_sitemap_index_content'] = [ $form_fragment[$prefix . 'simple_sitemap_index_content'] = [
'#type' => 'radios', '#type' => 'radios',
'#default_value' => $index, '#default_value' => $settings['index'],
'#options' => [ '#options' => [
0 => $this->getEntityCategory() === 'instance' ? $this->t('Do not index this @bundle entity', ['@bundle' => $bundle_name]) : $this->t('Do not index entities of this type'), 0 => $this->getEntityCategory() === 'instance'
1 => $this->getEntityCategory() === 'instance' ? $this->t('Index this @bundle entity', ['@bundle' => $bundle_name]) : $this->t('Index entities of this type'), ? $this->t('Do not index this @bundle entity', ['@bundle' => $bundle_name])
: $this->t('Do not index entities of this type'),
1 => $this->getEntityCategory() === 'instance'
? $this->t('Index this @bundle entity', ['@bundle' => $bundle_name])
: $this->t('Index entities of this type'),
], ],
]; ];
if ($this->getEntityCategory() === 'instance' && isset($bundle_settings['index'])) { if ($this->getEntityCategory() === 'instance' && isset($bundle_settings['index'])) {
$form_fragment[$prefix . 'simple_sitemap_index_content']['#options'][$bundle_settings['index']] .= ' <em>(' . $this->t('default') . ')</em>'; $form_fragment[$prefix . 'simple_sitemap_index_content']['#options'][$bundle_settings['index']] .= ' <em>(' . $this->t('default') . ')</em>';
} }
} }
// Priority
$form_fragment[$prefix . 'simple_sitemap_priority'] = [ $form_fragment[$prefix . 'simple_sitemap_priority'] = [
'#type' => 'select', '#type' => 'select',
'#title' => $this->t('Priority'), '#title' => $this->t('Priority'),
'#description' => $this->getEntityCategory() === 'instance' '#description' => $this->getEntityCategory() === 'instance'
? $this->t('The priority this @bundle entity will have in the eyes of search engine bots.', ['@bundle' => $bundle_name]) ? $this->t('The priority this @bundle entity will have in the eyes of search engine bots.', ['@bundle' => $bundle_name])
: $this->t('The priority entities of this type will have in the eyes of search engine bots.'), : $this->t('The priority entities of this type will have in the eyes of search engine bots.'),
'#default_value' => $priority, '#default_value' => $settings['priority'],
'#options' => $this->getPrioritySelectValues(), '#options' => $this->getPrioritySelectValues(),
]; ];
...@@ -269,13 +276,14 @@ class FormHelper { ...@@ -269,13 +276,14 @@ class FormHelper {
$form_fragment[$prefix . 'simple_sitemap_priority']['#options'][$this->formatPriority($bundle_settings['priority'])] .= ' (' . $this->t('default') . ')'; $form_fragment[$prefix . 'simple_sitemap_priority']['#options'][$this->formatPriority($bundle_settings['priority'])] .= ' (' . $this->t('default') . ')';
} }
// Changefreq
$form_fragment[$prefix . 'simple_sitemap_changefreq'] = [ $form_fragment[$prefix . 'simple_sitemap_changefreq'] = [
'#type' => 'select', '#type' => 'select',
'#title' => $this->t('Change frequency'), '#title' => $this->t('Change frequency'),
'#description' => $this->getEntityCategory() === 'instance' '#description' => $this->getEntityCategory() === 'instance'
? $this->t('The frequency with which this @bundle entity changes. Search engine bots may take this as an indication of how often to index it.', ['@bundle' => $bundle_name]) ? $this->t('The frequency with which this @bundle entity changes. Search engine bots may take this as an indication of how often to index it.', ['@bundle' => $bundle_name])
: $this->t('The frequency with which entities of this type change. Search engine bots may take this as an indication of how often to index them.'), : $this->t('The frequency with which entities of this type change. Search engine bots may take this as an indication of how often to index them.'),
'#default_value' => $changefreq, '#default_value' => $settings['changefreq'],
'#options' => $this->getChangefreqSelectValues(), '#options' => $this->getChangefreqSelectValues(),
]; ];
...@@ -283,13 +291,14 @@ class FormHelper { ...@@ -283,13 +291,14 @@ class FormHelper {
$form_fragment[$prefix . 'simple_sitemap_changefreq']['#options'][$bundle_settings['changefreq']] .= ' (' . $this->t('default') . ')'; $form_fragment[$prefix . 'simple_sitemap_changefreq']['#options'][$bundle_settings['changefreq']] .= ' (' . $this->t('default') . ')';
} }
// Images
$form_fragment[$prefix . 'simple_sitemap_include_images'] = [ $form_fragment[$prefix . 'simple_sitemap_include_images'] = [
'#type' => 'select', '#type' => 'select',
'#title' => $this->t('Include images'), '#title' => $this->t('Include images'),
'#description' => $this->getEntityCategory() === 'instance' '#description' => $this->getEntityCategory() === 'instance'
? $this->t('Determines if images referenced by this @bundle entity should be included in the sitemap.', ['@bundle' => $bundle_name]) ? $this->t('Determines if images referenced by this @bundle entity should be included in the sitemap.', ['@bundle' => $bundle_name])
: $this->t('Determines if images referenced by entities of this type should be included in the sitemap.'), : $this->t('Determines if images referenced by entities of this type should be included in the sitemap.'),
'#default_value' => $include_images, '#default_value' => $settings['include_images'],
'#options' => [0 => $this->t('No'), 1 => $this->t('Yes')], '#options' => [0 => $this->t('No'), 1 => $this->t('Yes')],
]; ];
...@@ -308,48 +317,48 @@ class FormHelper { ...@@ -308,48 +317,48 @@ class FormHelper {
* TRUE if this is a bundle or bundle instance form, FALSE otherwise. * TRUE if this is a bundle or bundle instance form, FALSE otherwise.
*/ */
protected function getEntityDataFromFormEntity() { protected function getEntityDataFromFormEntity() {
$form_entity = $this->getFormEntity(); if (FALSE === $form_entity = $this->getFormEntity()) {
if ($form_entity !== FALSE) { return FALSE;
$entity_type_id = $form_entity->getEntityTypeId(); }
$sitemap_entity_types = $this->entityHelper->getSupportedEntityTypes();
if (isset($sitemap_entity_types[$entity_type_id])) {
$this->setEntityCategory('instance');
}
else {
/**
* @var \Drupal\Core\Entity\EntityType $sitemap_entity_type
*/
foreach ($sitemap_entity_types as $sitemap_entity_type) {
if ($sitemap_entity_type->getBundleEntityType() == $entity_type_id) {
$this->setEntityCategory('bundle');
break;
}
}
}
// Menu fix.
$this->setEntityCategory(NULL === $this->getEntityCategory() && $entity_type_id == 'menu' ? 'bundle' : $this->getEntityCategory());
switch ($this->getEntityCategory()) {
case 'bundle':
$this->setEntityTypeId($this->entityHelper->getBundleEntityTypeId($form_entity));
$this->setBundleName($form_entity->id());
$this->setInstanceId(NULL);
break;
case 'instance': $entity_type_id = $form_entity->getEntityTypeId();
$this->setEntityTypeId($entity_type_id); $sitemap_entity_types = $this->entityHelper->getSupportedEntityTypes();
$this->setBundleName($this->entityHelper->getEntityInstanceBundleName($form_entity)); if (isset($sitemap_entity_types[$entity_type_id])) {
// New menu link's id is '' instead of NULL, hence checking for empty. $this->setEntityCategory('instance');
$this->setInstanceId(!empty($form_entity->id()) ? $form_entity->id() : NULL); }
else {
/**
* @var \Drupal\Core\Entity\EntityType $sitemap_entity_type
*/
foreach ($sitemap_entity_types as $sitemap_entity_type) {
if ($sitemap_entity_type->getBundleEntityType() === $entity_type_id) {
$this->setEntityCategory('bundle');
break; break;
}
default:
return FALSE;
} }
return TRUE;
} }
return FALSE;
// Menu fix.
$this->setEntityCategory(NULL === $this->getEntityCategory() && $entity_type_id == 'menu' ? 'bundle' : $this->getEntityCategory());
switch ($this->getEntityCategory()) {
case 'bundle':
$this->setEntityTypeId($this->entityHelper->getBundleEntityTypeId($form_entity));
$this->setBundleName($form_entity->id());
$this->setInstanceId(NULL);
break;
case 'instance':
$this->setEntityTypeId($entity_type_id);
$this->setBundleName($this->entityHelper->getEntityInstanceBundleName($form_entity));
// New menu link's id is '' instead of NULL, hence checking for empty.
$this->setInstanceId(!empty($form_entity->id()) ? $form_entity->id() : NULL);
break;
default:
return FALSE;
}
return TRUE;
} }
/** /**
......
...@@ -33,7 +33,7 @@ class SimplesitemapCustomLinksForm extends SimplesitemapFormBase { ...@@ -33,7 +33,7 @@ class SimplesitemapCustomLinksForm extends SimplesitemapFormBase {
'#type' => 'textarea', '#type' => 'textarea',
'#title' => $this->t('Relative Drupal paths'), '#title' => $this->t('Relative Drupal paths'),
'#default_value' => $this->customLinksToString($this->generator->getCustomLinks(FALSE)), '#default_value' => $this->customLinksToString($this->generator->getCustomLinks(FALSE)),
'#description' => $this->t("Please specify drupal internal (relative) paths, one per line. Do not forget to prepend the paths with a '/'.<br/>Optionally link priority <em>(0.0 - 1.0)</em> can be added by appending it after a space.<br/> Optionally link change frequency <em>(always / hourly / daily / weekly / monthly / yearly / never)</em> can be added by appending it after a space.<br/><br/><strong>Examples:</strong><br/><em>/ 1.0 daily</em> -> home page with the highest priority and daily change frequency<br/><em>/contact</em> -> contact page with the default priority and no change frequency information"), '#description' => $this->t('Please specify drupal internal (relative) paths, one per line. Do not forget to prepend the paths with a \'/\'.<br/>Optionally link priority <em>(0.0 - 1.0)</em> can be added by appending it after a space.<br/> Optionally link change frequency <em>(always / hourly / daily / weekly / monthly / yearly / never)</em> can be added by appending it after a space.<br/><br/><strong>Examples:</strong><br/><em>/ 1.0 daily</em> -> home page with the highest priority and daily change frequency<br/><em>/contact</em> -> contact page with the default priority and no change frequency information'),
]; ];
$form['simple_sitemap_custom']['include_images'] = [ $form['simple_sitemap_custom']['include_images'] = [
...@@ -67,22 +67,22 @@ class SimplesitemapCustomLinksForm extends SimplesitemapFormBase { ...@@ -67,22 +67,22 @@ class SimplesitemapCustomLinksForm extends SimplesitemapFormBase {
// if (!$this->pathValidator->getUrlIfValidWithoutAccessCheck($link_config['path']) //todo // if (!$this->pathValidator->getUrlIfValidWithoutAccessCheck($link_config['path']) //todo
// Path validator does not see a double slash as an error. Catching this to prevent breaking path generation. // Path validator does not see a double slash as an error. Catching this to prevent breaking path generation.
|| strpos($link_config['path'], '//') !== FALSE) { || strpos($link_config['path'], '//') !== FALSE) {
$form_state->setErrorByName('', $this->t("<strong>Line @line</strong>: The path <em>@path</em> does not exist.", $placeholders)); $form_state->setErrorByName('', $this->t('<strong>Line @line</strong>: The path <em>@path</em> does not exist.', $placeholders));
} }
// Making sure the paths start with a slash. // Making sure the paths start with a slash.
if ($link_config['path'][0] != '/') { if ($link_config['path'][0] != '/') {
$form_state->setErrorByName('', $this->t("<strong>Line @line</strong>: The path <em>@path</em> needs to start with a '/'.", $placeholders)); $form_state->setErrorByName('', $this->t('<strong>Line @line</strong>: The path <em>@path</em> needs to start with a \'/\'.', $placeholders));
} }
// Making sure the priority is formatted correctly. // Making sure the priority is formatted correctly.
if (isset($link_config['priority']) && !FormHelper::isValidPriority($link_config['priority'])) { if (isset($link_config['priority']) && !FormHelper::isValidPriority($link_config['priority'])) {
$form_state->setErrorByName('', $this->t("<strong>Line @line</strong>: The priority setting <em>@priority</em> for path <em>@path</em> is incorrect. Set the priority from 0.0 to 1.0.", $placeholders)); $form_state->setErrorByName('', $this->t('<strong>Line @line</strong>: The priority setting <em>@priority</em> for path <em>@path</em> is incorrect. Set the priority from 0.0 to 1.0.', $placeholders));
} }
// Making sure changefreq is formatted correctly. // Making sure changefreq is formatted correctly.
if (isset($link_config['changefreq']) && !FormHelper::isValidChangefreq($link_config['changefreq'])) { if (isset($link_config['changefreq']) && !FormHelper::isValidChangefreq($link_config['changefreq'])) {
$form_state->setErrorByName('', $this->t("<strong>Line @line</strong>: The changefreq setting <em>@changefreq</em> for path <em>@path</em> is incorrect. The following are the correct values: <em>@changefreq_options</em>.", $placeholders)); $form_state->setErrorByName('', $this->t('<strong>Line @line</strong>: The changefreq setting <em>@changefreq</em> for path <em>@path</em> is incorrect. The following are the correct values: <em>@changefreq_options</em>.', $placeholders));
} }
} }
} }
......
...@@ -27,7 +27,7 @@ class SimplesitemapEntitiesForm extends SimplesitemapFormBase { ...@@ -27,7 +27,7 @@ class SimplesitemapEntitiesForm extends SimplesitemapFormBase {
$form['simple_sitemap_entities']['entities'] = [ $form['simple_sitemap_entities']['entities'] = [
'#title' => $this->t('Sitemap entities'), '#title' => $this->t('Sitemap entities'),
'#type' => 'fieldset', '#type' => 'fieldset',
'#markup' => '<p>' . $this->t("Simple XML sitemap settings will be added only to entity forms of entity types enabled here. For all entity types featuring bundles (e.g. <em>node</em>) sitemap settings have to be set on their bundle pages (e.g. <em>page</em>).") . '</p>', '#markup' => '<p>' . $this->t('Simple XML sitemap settings will be added only to entity forms of entity types enabled here. For all entity types featuring bundles (e.g. <em>node</em>) sitemap settings have to be set on their bundle pages (e.g. <em>page</em>).') . '</p>',
]; ];
$form['#attached']['library'][] = 'simple_sitemap/sitemapEntities'; $form['#attached']['library'][] = 'simple_sitemap/sitemapEntities';
...@@ -60,9 +60,9 @@ class SimplesitemapEntitiesForm extends SimplesitemapFormBase { ...@@ -60,9 +60,9 @@ class SimplesitemapEntitiesForm extends SimplesitemapFormBase {
if ($form['simple_sitemap_entities']['entities'][$entity_type_id][$entity_type_id . '_enabled']['#default_value']) { if ($form['simple_sitemap_entities']['entities'][$entity_type_id][$entity_type_id . '_enabled']['#default_value']) {
$form['simple_sitemap_entities']['entities'][$entity_type_id][$entity_type_id . '_enabled']['#suffix'] $form['simple_sitemap_entities']['entities'][$entity_type_id][$entity_type_id . '_enabled']['#suffix']
= "<div id='warning-$css_entity_type_id'>" = '<div id="warning-' . $css_entity_type_id . '">'
. $this->t("<strong>Warning:</strong> This entity type's sitemap settings including per-entity overrides will be deleted after hitting <em>Save</em>.") . $this->t('<strong>Warning:</strong> This entity type\'s sitemap settings including per-entity overrides will be deleted after hitting <em>Save</em>.')
. "</div>"; . '</div>';
} }
$form['#attached']['drupalSettings']['simple_sitemap']['all_entities'][] = $css_entity_type_id; $form['#attached']['drupalSettings']['simple_sitemap']['all_entities'][] = $css_entity_type_id;
......
...@@ -86,7 +86,7 @@ abstract class SimplesitemapFormBase extends ConfigFormBase { ...@@ -86,7 +86,7 @@ abstract class SimplesitemapFormBase extends ConfigFormBase {
* *
*/ */
protected function getDonationText() { protected function getDonationText() {
return "<div class='description'>" . $this->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>"; return '<div class="description">' . $this->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>';
} }
} }
...@@ -102,7 +102,7 @@ class SimplesitemapSettingsForm extends SimplesitemapFormBase { ...@@ -102,7 +102,7 @@ class SimplesitemapSettingsForm extends SimplesitemapFormBase {
'#type' => 'number', '#type' => 'number',
'#title' => $this->t('Maximum links in a sitemap'), '#title' => $this->t('Maximum links in a sitemap'),
'#min' => 1, '#min' => 1,
'#description' => $this->t("The maximum number of links one sitemap can hold. If more links are generated than set here, a sitemap index will be created and the links split into several sub-sitemaps.<br/>50 000 links is the maximum Google will parse per sitemap, however it is advisable to set this to a lower number. If left blank, all links will be shown on a single sitemap."), '#description' => $this->t('The maximum number of links one sitemap can hold. If more links are generated than set here, a sitemap index will be created and the links split into several sub-sitemaps.<br/>50 000 links is the maximum Google will parse per sitemap, however it is advisable to set this to a lower number. If left blank, all links will be shown on a single sitemap.'),
'#default_value' => $this->generator->getSetting('max_links', 2000), '#default_value' => $this->generator->getSetting('max_links', 2000),
]; ];
...@@ -110,7 +110,7 @@ class SimplesitemapSettingsForm extends SimplesitemapFormBase { ...@@ -110,7 +110,7 @@ class SimplesitemapSettingsForm extends SimplesitemapFormBase {
'#type' => 'number', '#type' => 'number',
'#title' => $this->t('Refresh batch every n links'), '#title' => $this->t('Refresh batch every n links'),
'#min' => 1, '#min' => 1,
'#description' => $this->t("During sitemap generation, the batch process will issue a page refresh after n links processed to prevent PHP timeouts and memory exhaustion.<br/>Increasing this number will reduce the number of times Drupal has to bootstrap (thus speeding up the generation process), but will require more memory and less strict PHP timeout settings."), '#description' => $this->t('During sitemap generation, the batch process will issue a page refresh after n links processed to prevent PHP timeouts and memory exhaustion.<br/>Increasing this number will reduce the number of times Drupal has to bootstrap (thus speeding up the generation process), but will require more memory and less strict PHP timeout settings.'),
'#default_value' => $this->generator->getSetting('batch_process_limit', 1500), '#default_value' => $this->generator->getSetting('batch_process_limit', 1500),
'#required' => TRUE, '#required' => TRUE,
]; ];
......
...@@ -25,7 +25,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface; ...@@ -25,7 +25,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
*/ */
class CustomUrlGenerator extends UrlGeneratorBase { class CustomUrlGenerator extends UrlGeneratorBase {
const PATH_DOES_NOT_EXIST_OR_NO_ACCESS_MESSAGE = "The custom path @path has been omitted from the XML sitemap as it either does not exist, or it is not accessible to anonymous users. You can review custom paths <a href='@custom_paths_url'>here</a>."; const PATH_DOES_NOT_EXIST_OR_NO_ACCESS_MESSAGE = 'The custom path @path has been omitted from the XML sitemap as it either does not exist, or it is not accessible to anonymous users. You can review custom paths <a href="@custom_paths_url">here</a>.';
/** /**
...@@ -61,8 +61,7 @@ class CustomUrlGenerator extends UrlGeneratorBase { ...@@ -61,8 +61,7 @@ class CustomUrlGenerator extends UrlGeneratorBase {
EntityTypeManagerInterface $entity_type_manager, EntityTypeManagerInterface $entity_type_manager,
Logger $logger, Logger $logger,
EntityHelper $entityHelper, EntityHelper $entityHelper,
PathValidator $path_validator PathValidator $path_validator) {
) {
parent::__construct( parent::__construct(
$configuration, $configuration,
$plugin_id, $plugin_id,
......
...@@ -346,7 +346,7 @@ abstract class UrlGeneratorBase extends SimplesitemapPluginBase implements UrlGe ...@@ -346,7 +346,7 @@ abstract class UrlGeneratorBase extends SimplesitemapPluginBase implements UrlGe
// Update chunk count info. // Update chunk count info.
$this->setChunkCount(empty($this->getChunkCount()) ? 1 : ($this->getChunkCount() + 1)); $this->setChunkCount(empty($this->getChunkCount()) ? 1 : ($this->getChunkCount() + 1));
// Update remove links from array that have been generated. // Remove links from result array that have been generated.
$this->setBatchResults(array_slice($this->getBatchResults(), count($chunk_links))); $this->setBatchResults(array_slice($this->getBatchResults(), count($chunk_links)));
} }
} }
......
...@@ -89,12 +89,6 @@ class Simplesitemap { ...@@ -89,12 +89,6 @@ class Simplesitemap {
'include_images' => 0, 'include_images' => 0,
]; ];
protected static $generatorServices = [
'simple_sitemap.custom_url_generator',
'simple_sitemap.entity_url_generator',
'simple_sitemap.arbitrary_url_generator',
];
/** /**
* Simplesitemap constructor. * Simplesitemap constructor.
* @param \Drupal\simple_sitemap\SitemapGenerator $sitemapGenerator * @param \Drupal\simple_sitemap\SitemapGenerator $sitemapGenerator
...@@ -163,7 +157,7 @@ class Simplesitemap { ...@@ -163,7 +157,7 @@ class Simplesitemap {
* @return $this * @return $this
*/ */
public function saveSetting($name, $setting) { public function saveSetting($name, $setting) {
$this->configFactory->getEditable("simple_sitemap.settings") $this->configFactory->getEditable('simple_sitemap.settings')
->set($name, $setting)->save(); ->set($name, $setting)->save();
return $this; return $this;
} }
...@@ -212,7 +206,7 @@ class Simplesitemap { ...@@ -212,7 +206,7 @@ class Simplesitemap {
*/ */
protected function fetchSitemapChunkInfo() { protected function fetchSitemapChunkInfo() {
return $this->db return $this->db
->query("SELECT id, sitemap_created FROM {simple_sitemap}") ->query('SELECT id, sitemap_created FROM {simple_sitemap}')
->fetchAllAssoc('id'); ->fetchAllAssoc('id');
} }