Unverified Commit 959c7b52 authored by Dave Reid's avatar Dave Reid Committed by Dave Reid

Issue #3042673 by Dave Reid, Sergiu Stici, ChristianAdamski, KarimB, Nikhilesh...

Issue #3042673 by Dave Reid, Sergiu Stici, ChristianAdamski, KarimB, Nikhilesh Gupta, Tolyan4ik, Saphyel, amateescu, RajeevChoudhary, voleger, kkalaskar, thalles: Removed Drupal 9 deprecated code and fixed coding standards.
parent 919a0159
......@@ -76,7 +76,7 @@ class XmlSitemapCommands extends DrushCommands {
// Build a list of rebuildable link types.
$rebuild_types = xmlsitemap_get_rebuildable_link_types();
if (empty($rebuild_types)) {
drush_log(dt('No link types are rebuildable.'), 'warning');
$this->logger()->warning(dt('No link types are rebuildable.'));
}
$batch = xmlsitemap_rebuild_batch($rebuild_types, TRUE);
......
......@@ -51,7 +51,7 @@ class XmlSitemapController extends ControllerBase {
* @param \Symfony\Component\HttpFoundation\Request $request
* The request object.
*
* @throws NotFoundHttpException
* @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
*
* @return \Symfony\Component\HttpFoundation\Response
* The sitemap in XML format or plain text if xmlsitemap_developer_mode flag
......
......@@ -11,17 +11,6 @@ use Drupal\Core\Form\FormStateInterface;
*/
class XmlSitemapDeleteForm extends EntityConfirmFormBase {
/**
* {@inheritdoc}
*
* @codingStandardsIgnoreStart
*/
public function getBaseFormID() {
// @codingStandardsIgnoreEnd
return 'xmlsitemap_delete_form';
}
/**
* {@inheritdoc}
*/
......@@ -48,7 +37,7 @@ class XmlSitemapDeleteForm extends EntityConfirmFormBase {
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->entity->delete();
drupal_set_message($this->t('Sitemap %label has been deleted.', ['%label' => $this->entity->label()]));
$this->messenger()->addStatus($this->t('Sitemap %label has been deleted.', ['%label' => $this->entity->label()]));
$form_state->setRedirect('xmlsitemap.admin_search');
}
......
......@@ -197,7 +197,7 @@ class XmlSitemapEntitiesSettingsForm extends ConfigFormBase {
if (!$values['settings'][$key]['types'][$bundle_key]) {
xmlsitemap_link_bundle_delete($key, $bundle_key, TRUE);
}
else if (!xmlsitemap_link_bundle_check_enabled($key, $bundle_key)) {
elseif (!xmlsitemap_link_bundle_check_enabled($key, $bundle_key)) {
xmlsitemap_link_bundle_enable($key, $bundle_key);
}
}
......
......@@ -73,18 +73,18 @@ class XmlSitemapForm extends EntityForm {
try {
$status = $this->entity->save();
if ($status == SAVED_NEW) {
drupal_set_message($this->t('Saved the %label sitemap.', [
$this->messenger()->addStatus($this->t('Saved the %label sitemap.', [
'%label' => $this->entity->label(),
]));
}
elseif ($status == SAVED_UPDATED) {
drupal_set_message($this->t('Updated the %label sitemap.', [
$this->messenger()->addStatus($this->t('Updated the %label sitemap.', [
'%label' => $this->entity->label(),
]));
}
}
catch (EntityStorageException $ex) {
drupal_set_message($this->t('There is another sitemap saved with the same context.'), 'error');
$this->messenger()->addError($this->t('There is another sitemap saved with the same context.'));
}
$form_state->setRedirect('xmlsitemap.admin_search');
......
......@@ -94,7 +94,7 @@ class XmlSitemapLinkBundleSettingsForm extends ConfigFormBase {
$entity_info = $form['xmlsitemap']['#entity_info'];
if (!empty($form['xmlsitemap']['#show_message'])) {
drupal_set_message($this->t('XML sitemap settings for the %bundle have been saved.', ['%bundle' => $entity_info['bundles'][$bundle]['label']]));
$this->messenger()->addStatus($this->t('XML sitemap settings for the %bundle have been saved.', ['%bundle' => $entity_info['bundles'][$bundle]['label']]));
}
// Unset the form values since we have already saved the bundle settings and
......
......@@ -66,13 +66,13 @@ class XmlSitemapRebuildForm extends ConfigFormBase {
$request = $this->getRequest();
if (!$request->request && !$this->state->get('xmlsitemap_rebuild_needed')) {
if (!$this->state->get('xmlsitemap_regenerate_needed')) {
drupal_set_message(t('Your sitemap is up to date and does not need to be rebuilt.'), 'error');
$this->messenger()->addError($this->t('Your sitemap is up to date and does not need to be rebuilt.'));
}
else {
$request->query->set('destination', 'admin/config/search/xmlsitemap');
drupal_set_message(t('A rebuild is not necessary. If you are just wanting to regenerate the XML sitemap files, you can <a href="@link-cron">run cron manually</a>.', [
$this->messenger()->addWarning($this->t('A rebuild is not necessary. If you are just wanting to regenerate the XML sitemap files, you can <a href="@link-cron">run cron manually</a>.', [
'@link-cron' => Url::fromRoute('system.run_cron', [], ['query' => $this->getDestinationArray()]),
]), 'warning');
]));
$this->setRequest($request);
}
}
......@@ -82,8 +82,8 @@ class XmlSitemapRebuildForm extends ConfigFormBase {
$rebuild_types = array_combine($rebuild_types, $rebuild_types);
$form['entity_type_ids'] = [
'#type' => 'select',
'#title' => t('Select which link types you would like to rebuild'),
'#description' => t('If no link types are selected, the sitemap files will just be regenerated.'),
'#title' => $this->t('Select which link types you would like to rebuild'),
'#description' => $this->t('If no link types are selected, the sitemap files will just be regenerated.'),
'#multiple' => TRUE,
'#options' => $rebuild_types,
'#default_value' => $this->state->get('xmlsitemap_rebuild_needed') || !$this->state->get('xmlsitemap_developer_mode') ? $rebuild_types : [],
......@@ -91,7 +91,7 @@ class XmlSitemapRebuildForm extends ConfigFormBase {
];
$form['save_custom'] = [
'#type' => 'checkbox',
'#title' => t('Save and restore any custom inclusion and priority links.'),
'#title' => $this->t('Save and restore any custom inclusion and priority links.'),
'#default_value' => TRUE,
];
return parent::buildForm($form, $form_state);
......
......@@ -199,7 +199,7 @@ class XmlSitemapSettingsForm extends ConfigFormBase {
'#default_value' => $config->get('lastmod_format'),
];
foreach ($form['advanced']['lastmod_format']['#options'] as $key => &$label) {
$label .= ' (' . gmdate($key, REQUEST_TIME) . ')';
$label .= ' (' . gmdate($key) . ')';
}
$form['advanced']['xmlsitemap_developer_mode'] = [
'#type' => 'checkbox',
......
......@@ -3,6 +3,7 @@
namespace Drupal\xmlsitemap\Tests;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\xmlsitemap\Entity\XmlSitemap;
/**
* Tests the sitemaps list builder.
......@@ -98,14 +99,14 @@ class XmlSitemapListBuilderTest extends XmlSitemapTestBase {
$this->drupalPostForm('admin/config/search/xmlsitemap/add', $edit, t('Save'));
$this->assertText(t('There is another sitemap saved with the same context.'));
$sitemaps = entity_load_multiple('xmlsitemap');
$sitemaps = XmlSitemap::loadMultiple();
foreach ($sitemaps as $sitemap) {
$label = $sitemap->label();
$this->drupalPostForm("admin/config/search/xmlsitemap/{$sitemap->id()}/delete", [], t('Delete'));
$this->assertRaw(t("Sitemap %label has been deleted.", ['%label' => $label]));
}
$sitemaps = entity_load_multiple('xmlsitemap');
$sitemaps = XmlSitemap::loadMultiple();
$this->assertEqual(count($sitemaps), 0, t('No more sitemaps.'));
}
......
......@@ -2,11 +2,15 @@
namespace Drupal\xmlsitemap\Tests;
use Drupal\Core\Entity\Entity\EntityFormDisplay;
use Drupal\Core\Entity\Entity\EntityViewDisplay;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\taxonomy\Entity\Term;
use Drupal\taxonomy\Entity\Vocabulary;
use Drupal\user\Entity\Role;
/**
......@@ -62,7 +66,7 @@ class XmlSitemapNodeFunctionalTest extends XmlSitemapTestBase {
]);
// Add a vocabulary so we can test different view modes.
$vocabulary = entity_create('taxonomy_vocabulary', [
$vocabulary = Vocabulary::create([
'name' => 'Tags',
'description' => $this->randomMachineName(),
'vid' => 'tags',
......@@ -89,19 +93,19 @@ class XmlSitemapNodeFunctionalTest extends XmlSitemapTestBase {
'bundle' => 'page',
])->save();
entity_get_form_display('node', 'page', 'default')
EntityFormDisplay::load('node.page.default')
->setComponent($field_name, [
'type' => 'entity_reference_autocomplete_tags',
])
->save();
// Show on default display and teaser.
entity_get_display('node', 'page', 'default')
EntityViewDisplay::load('node.page.default')
->setComponent($field_name, [
'type' => 'entity_reference_label',
])
->save();
entity_get_display('node', 'page', 'teaser')
EntityViewDisplay::load('node.page.teaser')
->setComponent($field_name, [
'type' => 'entity_reference_label',
])
......@@ -125,7 +129,7 @@ class XmlSitemapNodeFunctionalTest extends XmlSitemapTestBase {
$edit['status[value]'] = TRUE;
$this->drupalPostForm('node/add/page', $edit, t('Save'));
$tags = entity_load_multiple('taxonomy_term');
$tags = Term::loadMultiple();
foreach ($tags as $tag) {
$this->assertSitemapLinkValues('taxonomy_term', $tag->id(), [
'status' => 0,
......@@ -143,7 +147,7 @@ class XmlSitemapNodeFunctionalTest extends XmlSitemapTestBase {
$this->drupalPostForm('node/add/page', $edit, t('Save'));
$tags = entity_load_multiple('taxonomy_term');
$tags = Term::loadMultiple();
foreach ($tags as $tag) {
$this->assertSitemapLinkValues('taxonomy_term', $tag->id(), [
'status' => 1,
......@@ -273,7 +277,7 @@ class XmlSitemapNodeFunctionalTest extends XmlSitemapTestBase {
}
// Clear all the node link data so we can emulate 'old' nodes.
db_delete('xmlsitemap')
\Drupal::database()->delete('xmlsitemap')
->condition('type', 'node')
->execute();
......
......@@ -388,7 +388,7 @@ abstract class XmlSitemapTestBase extends WebTestBase {
return [];
}
$query = db_select('watchdog');
$query = \Drupal::database()->select('watchdog');
$query->fields('watchdog', [
'wid',
'type',
......
This diff is collapsed.
......@@ -86,7 +86,7 @@ interface XmlSitemapGeneratorInterface {
* The XML sitemap config entity.
* @param int|null $pages
* The number of pages to write in the sitemap. Defaults to the value of
* @code $sitemap->getChunks() @endcode.
* $sitemap->getChunks().
*/
public function generateIndex(XmlSitemapInterface $sitemap, $pages = NULL);
......@@ -142,7 +142,7 @@ interface XmlSitemapGeneratorInterface {
*
* @param string $entity_type_id
* Entity type to be rebuilt.
* @param array $context
* @param array|\ArrayAccess $context
* Context to be rebuilt.
*/
public function rebuildBatchFetch($entity_type_id, &$context);
......
......@@ -144,7 +144,11 @@ class XmlSitemapLinkStorage implements XmlSitemapLinkStorageInterface {
// Throw an error with the link does not start with a slash.
// @see \Drupal\Core\Url::fromInternalUri()
if ($link['loc'][0] !== '/') {
trigger_error(t('The XML sitemap link path %path for @type @id is invalid because it does not start with a slash.', ['%path' => $link['loc'], '@type' => $link['type'], '@id' => $link['id']]), E_USER_ERROR);
trigger_error(t('The XML sitemap link path %path for @type @id is invalid because it does not start with a slash.', [
'%path' => $link['loc'],
'@type' => $link['type'],
'@id' => $link['id'],
]), E_USER_ERROR);
}
// Check if this is a changed link and set the regenerate flag if necessary.
......@@ -188,7 +192,7 @@ class XmlSitemapLinkStorage implements XmlSitemapLinkStorageInterface {
/**
* {@inheritdoc}
*/
public function checkChangedLink(array $link, $original_link = NULL, $flag = FALSE) {
public function checkChangedLink(array $link, array $original_link = NULL, $flag = FALSE) {
$changed = FALSE;
if ($original_link === NULL) {
......@@ -276,7 +280,7 @@ class XmlSitemapLinkStorage implements XmlSitemapLinkStorageInterface {
/**
* {@inheritdoc}
*/
public function updateMultiple($updates = [], $conditions = [], $check_flag = TRUE) {
public function updateMultiple(array $updates = [], array $conditions = [], $check_flag = TRUE) {
// If we are going to modify a visible sitemap link, we will need to set
// the regenerate needed flag.
if ($check_flag && !$this->state->get('xmlsitemap_regenerate_needed')) {
......
......@@ -42,10 +42,8 @@ interface XmlSitemapLinkStorageInterface {
*
* @return bool
* TRUE if the link is changed, or FALSE otherwise.
*
* @codingStandardsIgnoreStart
*/
public function checkChangedLink(array $link, $original_link = NULL, $flag = FALSE);
public function checkChangedLink(array $link, array $original_link = NULL, $flag = FALSE);
/**
* Check if there is a visible sitemap link given a certain set of conditions.
......@@ -60,8 +58,6 @@ interface XmlSitemapLinkStorageInterface {
*
* @return bool
* TRUE if there is a visible link, or FALSE otherwise.
*
* @codingStandardsIgnoreEnd
*/
public function checkChangedLinks(array $conditions = [], array $updates = [], $flag = FALSE);
......@@ -114,10 +110,8 @@ interface XmlSitemapLinkStorageInterface {
*
* @return int
* The number of links that were updated.
*
* @codingStandardsIgnoreStart
*/
public function updateMultiple($updates = [], $conditions = [], $check_flag = TRUE);
public function updateMultiple(array $updates = [], array $conditions = [], $check_flag = TRUE);
/**
* Load a specific sitemap link from the database.
......@@ -129,8 +123,6 @@ interface XmlSitemapLinkStorageInterface {
*
* @return array
* A sitemap link (array) or FALSE if the conditions were not found.
*
* @codingStandardsIgnoreEnd
*/
public function load($entity_type, $entity_id);
......
......@@ -113,7 +113,7 @@ class XmlSitemapWriter extends \XMLWriter {
throw new XmlSitemapGenerationException(t('Unknown error occurred while writing to file @file.', ['@file' => $this->uri]));
}
if (\Drupal::config('xmlsitemap.settings')->get('xsl')) {
$this->writeXSL();
$this->writeXsl();
}
$this->startElement($this->isIndex() ? 'sitemapindex' : 'urlset', TRUE);
return $result;
......@@ -122,7 +122,7 @@ class XmlSitemapWriter extends \XMLWriter {
/**
* Adds the XML stylesheet to the XML page.
*/
public function writeXSL() {
public function writeXsl() {
$xls_url = Url::fromRoute('xmlsitemap.sitemap_xsl')->toString();
$settings = \Drupal::config('language.negotiation');
if ($settings) {
......@@ -175,8 +175,8 @@ class XmlSitemapWriter extends \XMLWriter {
parent::startElement($name);
if ($root) {
foreach ($this->getRootAttributes() as $name => $value) {
$this->writeAttribute($name, $value);
foreach ($this->getRootAttributes() as $key => $value) {
$this->writeAttribute($key, $value);
}
$this->writeRaw(PHP_EOL);
}
......@@ -228,11 +228,8 @@ class XmlSitemapWriter extends \XMLWriter {
*
* @return string
* Document uri.
*
* @codingStandardsIgnoreStart
*/
public function getURI() {
// @codingStandardsIgnoreEnd
public function getUri() {
return $this->uri;
}
......@@ -284,11 +281,21 @@ class XmlSitemapWriter extends \XMLWriter {
*
* The extra whitespace has been removed.
*
* @param $array
* @param array $array
* An array where each item represents an element and is either a:
* - (key => value) pair (<key>value</key>)
* - Associative array with fields:
* - 'key': element name
* - 'value': element contents
* - 'attributes': associative array of element attributes or an
* \Drupal\Core\Template\Attribute object
* In both cases, 'value' can be a simple string, or it can be another
* array with the same format as $array itself for nesting.
*
* @return string
* The XML output.
*/
public static function formatXmlElements($array) {
public static function formatXmlElements(array $array) {
$output = '';
foreach ($array as $key => $value) {
if (is_numeric($key)) {
......@@ -301,10 +308,10 @@ class XmlSitemapWriter extends \XMLWriter {
$output .= static::toString($value['attributes']);
}
if (isset($value['value']) && $value['value'] != '') {
$output .= '>' . (is_array($value['value']) ? static::formatXmlElements($value['value']) : Html::escape(static::toString($value['value']))) . '</' . $value['key'] . ">";
$output .= '>' . (is_array($value['value']) ? static::formatXmlElements($value['value']) : Html::escape(static::toString($value['value']))) . '</' . $value['key'] . '>';
}
else {
$output .= " />";
$output .= ' />';
}
}
}
......@@ -322,6 +329,7 @@ class XmlSitemapWriter extends \XMLWriter {
* The value to turn into a string.
*
* @return string
* The string value.
*/
public static function toString($value) {
if (is_object($value)) {
......
......@@ -28,14 +28,17 @@ class DirectoryTest extends KernelTestBase {
* @covers ::_xmlsitemap_delete_recursive
*/
public function testClearDirectory() {
/** @var \Drupal\Core\File\FileSystemInterface $fileSystem */
$fileSystem = $this->container->get('file_system');
// Set up a couple more directories and files.
$directory = 'public://not-xmlsitemap';
file_prepare_directory($directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
$fileSystem->prepareDirectory($directory, $fileSystem::CREATE_DIRECTORY | $fileSystem::MODIFY_PERMISSIONS);
$directory = 'public://xmlsitemap/test';
file_prepare_directory($directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
file_unmanaged_save_data('File unrelated to XML sitemap', 'public://not-xmlsitemap/file.txt');
file_unmanaged_save_data('File unrelated to XML sitemap', 'public://file.txt');
file_unmanaged_save_data('Test contents', 'public://xmlsitemap/test/index.xml');
$fileSystem->prepareDirectory($directory, $fileSystem::CREATE_DIRECTORY | $fileSystem::MODIFY_PERMISSIONS);
$fileSystem->saveData('File unrelated to XML sitemap', 'public://not-xmlsitemap/file.txt');
$fileSystem->saveData('File unrelated to XML sitemap', 'public://file.txt');
$fileSystem->saveData('Test contents', 'public://xmlsitemap/test/index.xml');
// Set the directory to an empty value.
\Drupal::configFactory()->getEditable('xmlsitemap.settings')->clear('path')->save();
......@@ -53,7 +56,7 @@ class DirectoryTest extends KernelTestBase {
drupal_static_reset('xmlsitemap_get_directory');
$result = xmlsitemap_clear_directory(NULL, TRUE);
// Test that only the xmlsitemap directory was deleted..xml');
// Test that only the xmlsitemap directory was deleted.
$this->assertDirectoryNotExists('public://xmlsitemap/test');
$this->assertDirectoryExists('public://not-xmlsitemap');
$this->assertFileExists('public://file.txt');
......
......@@ -63,7 +63,7 @@ class XmlSitemapWriterTest extends KernelTestBase {
$expected = '<url><item1>value1</item1><item2>&lt;value2&gt;</item2><item3 attr1key="attr1value" attr2key="&lt;attr2value&gt;"><subkey>subvalue</subkey></item3></url>' . PHP_EOL;
$this->assertEquals($expected, $output);
$writer->writeSitemapElement('url', [
$writer->writeElement('url', [
'loc' => 'https://www.example.com/test',
'image:image' => [
'image:loc' => 'https://www.example.com/test.jpg',
......
......@@ -61,11 +61,11 @@ function drush_xmlsitemap_rebuild() {
*/
function drush_xmlsitemap_index() {
$limit = (int) drush_get_option('limit', \Drupal::config('xmlsitemap.settings')->get('batch_limit'));
$count_before = db_select('xmlsitemap', 'x')->countQuery()->execute()->fetchField();
$count_before = \Drupal::database()->select('xmlsitemap', 'x')->countQuery()->execute()->fetchField();
\Drupal::moduleHandler()->invokeAll('xmlsitemap_index_links', ['limit' => $limit]);
$count_after = db_select('xmlsitemap', 'x')->countQuery()->execute()->fetchField();
$count_after = \Drupal::database()->select('xmlsitemap', 'x')->countQuery()->execute()->fetchField();
if ($count_after == $count_before) {
drush_print(dt('No new XML sitemap links to index.'));
......
......@@ -7,7 +7,6 @@
* @ingroup xmlsitemap
*/
use Drupal\Core\Database\Database;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Session\AnonymousUserSession;
use Drupal\Core\Url;
......@@ -121,7 +120,7 @@ function xmlsitemap_requirements($phase) {
// Check when the cached files were last generated.
$generated_last = \Drupal::state()->get('xmlsitemap_generated_last', 0);
$generated_ago = REQUEST_TIME - $generated_last;
$generated_ago = \Drupal::time()->getRequestTime() - $generated_last;
$requirements['xmlsitemap_generated'] = [
'title' => $t('XML sitemap'),
'value' => $generated_last ? $t('Last attempted generation on @date (@interval ago).', [
......@@ -142,7 +141,7 @@ function xmlsitemap_requirements($phase) {
if (!\Drupal::config('xmlsitemap.settings')->get('disable_cron_regeneration')) {
$last_run = max($generated_last, \Drupal::state()->get('system.cron_last', 0), \Drupal::state()->get('install_time', 0));
}
$last_run_ago = REQUEST_TIME - $last_run;
$last_run_ago = \Drupal::time()->getRequestTime() - $last_run;
$cron_warning_threshold = \Drupal::config('system.cron')->get('threshold.requirements_warning');
$cron_error_threshold = \Drupal::config('system.cron')->get('threshold.requirements_error');
if ($max_filesize == 0) {
......@@ -303,7 +302,7 @@ function xmlsitemap_install() {
// Insert the homepage link into the {xmlsitemap} table so we do not show an
// empty sitemap after install.
db_insert('xmlsitemap')
\Drupal::database()->insert('xmlsitemap')
->fields([
'type' => 'frontpage',
'id' => 0,
......
This diff is collapsed.
services:
xmlsitemap_generator:
class: Drupal\xmlsitemap\XmlSitemapGenerator
arguments: ['@config.factory', '@state', '@language_manager', '@logger.channel.xmlsitemap', '@module_handler', '@entity_type.manager', '@database']
arguments: ['@config.factory', '@state', '@language_manager', '@logger.channel.xmlsitemap', '@module_handler', '@entity_type.manager', '@database', '@messenger', '@file_system', '@datetime.time']
tags:
- { name: xmlsitemap_generator }
xmlsitemap.link_storage:
......
......@@ -4,14 +4,44 @@ namespace Drupal\xmlsitemap_custom\Controller;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Database\Connection;
use Drupal\Core\Database\Query\PagerSelectExtender;
use Drupal\Core\Database\Query\TableSortExtender;
use Drupal\Core\Link;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Builds the list table for all custom links.
*/
class XmlSitemapCustomListController extends ControllerBase {
/**
* The database connection.
*
* @var \Drupal\Core\Database\Connection
*/
protected $connection;
/**
* XmlSitemapCustomListController constructor.
*
* @param \Drupal\Core\Database\Connection $connection
* The database connection.
*/
public function __construct(Connection $connection) {
$this->connection = $connection;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('database')
);
}
/**
* Renders a list with all custom links.
*
......@@ -34,11 +64,11 @@ class XmlSitemapCustomListController extends ControllerBase {
$rows = [];
$query = db_select('xmlsitemap');
$query = $this->connection->select('xmlsitemap');
$query->fields('xmlsitemap');
$query->condition('type', 'custom');
$query->extend('Drupal\Core\Database\Query\PagerSelectExtender')->limit(50);
$query->extend('Drupal\Core\Database\Query\TableSortExtender')->orderByHeader($header);
$query->extend(PagerSelectExtender::class)->limit(50);
$query->extend(TableSortExtender::class)->orderByHeader($header);
$result = $query->execute();
foreach ($result as $link) {
......
......@@ -241,7 +241,7 @@ class XmlSitemapCustomAddForm extends FormBase {
$form_state->cleanValues();
$link = $form_state->getValues();
$this->linkStorage->save($link);
$this->messenger()->addMessage($this->t('The custom link for %loc was saved.', ['%loc' => $link['loc']]));
$this->messenger()->addStatus($this->t('The custom link for %loc was saved.', ['%loc' => $link['loc']]));
$form_state->setRedirect('xmlsitemap_custom.list');
}
......
......@@ -98,7 +98,7 @@ class XmlSitemapCustomDeleteForm extends ConfirmFormBase {
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->linkStorage->delete('custom', $this->custom_link['id']);
$this->logger('xmlsitemap')->debug('The custom link for %loc has been deleted.', ['%loc' => $this->custom_link['loc']]);
drupal_set_message($this->t('The custom link for %loc has been deleted.', ['%loc' => $this->custom_link['loc']]));
$this->messenger()->addStatus($this->t('The custom link for %loc has been deleted.', ['%loc' => $this->custom_link['loc']]));
$form_state->setRedirectUrl($this->getCancelUrl());
}
......
......@@ -10,8 +10,6 @@ use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\Path\AliasManagerInterface;
use Drupal\Core\Url;
use Drupal\xmlsitemap\XmlSitemapLinkStorageInterface;
use GuzzleHttp\Exception\ClientException;
use GuzzleHttp\Exception\ConnectException;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
......@@ -203,7 +201,7 @@ class XmlSitemapCustomEditForm extends FormBase {
$form_state->cleanValues();
$link = $form_state->getValues();
$this->linkStorage->save($link);
$this->messenger()->addMessage($this->t('The custom link for %loc was saved.', ['%loc' => $link['loc']]));
$this->messenger()->addStatus($this->t('The custom link for %loc was saved.', ['%loc' => $link['loc']]));
$form_state->setRedirect('xmlsitemap_custom.list');
}
......
......@@ -82,7 +82,7 @@ function xmlsitemap_engines_submit_access() {
}