diff --git a/src/Form/XmlSitemapForm.php b/src/Form/XmlSitemapForm.php index 3dd2a02b93cedd80bd7b6368abe50afb88fc5c7c..5823bd788ce5bc34c6372d283f09eb4330cb3ed5 100644 --- a/src/Form/XmlSitemapForm.php +++ b/src/Form/XmlSitemapForm.php @@ -45,7 +45,7 @@ class XmlSitemapForm extends EntityForm { if (empty($visible_children)) { $form['context']['empty'] = [ '#type' => 'markup', - '#markup' => '

' . t('There are currently no XML sitemap contexts available.') . '

', + '#markup' => '

' . $this->t('There are currently no XML sitemap contexts available.') . '

', ]; } diff --git a/src/XmlSitemapGenerator.php b/src/XmlSitemapGenerator.php index 1bc050bff55c9ad1f53ca9922fba64e37a55c05b..b5ae1b100f89d92feba459c2cb01bbc69e2053e3 100644 --- a/src/XmlSitemapGenerator.php +++ b/src/XmlSitemapGenerator.php @@ -303,11 +303,7 @@ class XmlSitemapGenerator implements XmlSitemapGeneratorInterface { // Ensure every link starts 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("The XML sitemap link path {$link['loc']} for {$link['type']} {$link['id']} is invalid because it does not start with a slash.", E_USER_ERROR); $link['loc'] = '/' . $link['loc']; } @@ -505,7 +501,7 @@ class XmlSitemapGenerator implements XmlSitemapGeneratorInterface { $query->execute(); } - $context['message'] = t('Links cleared'); + $context['message'] = $this->t('Links cleared'); } /** @@ -558,7 +554,7 @@ class XmlSitemapGenerator implements XmlSitemapGeneratorInterface { $info['xmlsitemap']['process callback']($entity_type_id, $result); $context['sandbox']['last_id'] = end($result); $context['sandbox']['progress'] += count($result); - $context['message'] = t('Processed %entity_type_id @last_id (@progress of @count).', [ + $context['message'] = $this->t('Processed %entity_type_id @last_id (@progress of @count).', [ '%entity_type_id' => $entity_type_id, '@last_id' => $context['sandbox']['last_id'], '@progress' => $context['sandbox']['progress'], @@ -581,7 +577,7 @@ class XmlSitemapGenerator implements XmlSitemapGeneratorInterface { $this->messenger->addStatus($this->t('The sitemap links were rebuilt.')); } else { - $this->messenger->addError(t('The sitemap links were not successfully rebuilt.')); + $this->messenger->addError($this->t('The sitemap links were not successfully rebuilt.')); } } diff --git a/src/XmlSitemapLinkStorage.php b/src/XmlSitemapLinkStorage.php index 0de069a43295ce04e17fd8ae086bc6ddea79b69a..8661121f42ee937bf336f4d5c0667462c0020eca 100644 --- a/src/XmlSitemapLinkStorage.php +++ b/src/XmlSitemapLinkStorage.php @@ -5,11 +5,11 @@ namespace Drupal\xmlsitemap; use Drupal\Core\Database\Connection; use Drupal\Core\Database\Query\Merge; use Drupal\Core\Entity\EntityChangedInterface; -use Drupal\Core\Language\LanguageInterface; -use Drupal\Core\Extension\ModuleHandlerInterface; -use Drupal\Core\State\StateInterface; use Drupal\Core\Entity\EntityInterface; +use Drupal\Core\Extension\ModuleHandlerInterface; +use Drupal\Core\Language\LanguageInterface; use Drupal\Core\Session\AnonymousUserSession; +use Drupal\Core\State\StateInterface; use Symfony\Component\Routing\Exception\RouteNotFoundException; /** @@ -128,27 +128,17 @@ class XmlSitemapLinkStorage implements XmlSitemapLinkStorageInterface { // Temporary validation checks. // @todo Remove in final? if ($link['priority'] < 0 || $link['priority'] > 1) { - trigger_error(t('Invalid sitemap link priority %priority.
@link', [ - '%priority' => $link['priority'], - '@link' => var_export($link, TRUE), - ]), E_USER_ERROR); + trigger_error("The XML sitemap link for {$link['type']} {$link['id']} has an invalid priority of {$link['priority']}.
" . var_export($link, TRUE), E_USER_ERROR); } if ($link['changecount'] < 0) { - trigger_error(t('Negative changecount value. Please report this to @516928.
@link', [ - '@516928' => 'https://www.drupal.org/node/516928', - '@link' => var_export($link, TRUE), - ]), E_USER_ERROR); + trigger_error("The XML sitemap link for {$link['type']} {$link['id']} has a negative changecount value. Please report this to https://www.drupal.org/node/516928.
" . var_export($link, TRUE), E_USER_ERROR); $link['changecount'] = 0; } // 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("The XML sitemap link path {$link['loc']} for {$link['type']} {$link['id']} is invalid because it does not start with a slash.", E_USER_ERROR); } // Check if this is a changed link and set the regenerate flag if necessary. diff --git a/src/XmlSitemapWriter.php b/src/XmlSitemapWriter.php index 063c06a6067f4c7e0e4289a9c9161cb63e3889bd..70885e35c58015b66fec0b9aa71a9b1230f70845 100644 --- a/src/XmlSitemapWriter.php +++ b/src/XmlSitemapWriter.php @@ -85,7 +85,7 @@ class XmlSitemapWriter extends \XMLWriter { public function openUri($uri) { $return = parent::openUri($uri); if (!$return) { - throw new XmlSitemapGenerationException(t('Could not open file @file for writing.', ['@file' => $uri])); + throw new XmlSitemapGenerationException("Could not open file $uri for writing."); } return $return; } @@ -110,7 +110,7 @@ class XmlSitemapWriter extends \XMLWriter { $this->setIndent(FALSE); $result = parent::startDocument($version, $encoding); if (!$result) { - throw new XmlSitemapGenerationException(t('Unknown error occurred while writing to file @file.', ['@file' => $this->uri])); + throw new XmlSitemapGenerationException("Unknown error occurred while writing to file {$this->uri}."); } if (\Drupal::config('xmlsitemap.settings')->get('xsl')) { $this->writeXsl(); @@ -255,7 +255,7 @@ class XmlSitemapWriter extends \XMLWriter { $return = parent::endDocument(); if (!$return) { - throw new XmlSitemapGenerationException(t('Unknown error occurred while writing to file @file.', ['@file' => $this->uri])); + throw new XmlSitemapGenerationException("Unknown error occurred while writing to file {$this->uri}."); } if (xmlsitemap_var('gz')) { diff --git a/tests/src/Kernel/XmlSitemapWriterTest.php b/tests/src/Kernel/XmlSitemapWriterTest.php index 1c1f270e037ee457022e93cf0f6846504abf123b..2055afe4f98bbb03b388d8214195b9428b82c68f 100644 --- a/tests/src/Kernel/XmlSitemapWriterTest.php +++ b/tests/src/Kernel/XmlSitemapWriterTest.php @@ -2,6 +2,8 @@ namespace Drupal\Tests\xmlsitemap\Kernel; +use Drupal\Core\StringTranslation\TranslatableMarkup; +use Drupal\Core\Url; use Drupal\xmlsitemap\Entity\XmlSitemap; use Drupal\xmlsitemap\XmlSitemapWriter; @@ -66,8 +68,8 @@ class XmlSitemapWriterTest extends KernelTestBase { $writer->writeElement('url', [ 'loc' => 'https://www.example.com/test', 'image:image' => [ - 'image:loc' => 'https://www.example.com/test.jpg', - 'image:title' => t('The image title'), + 'image:loc' => Url::fromUri('https://www.example.com/test.jpg'), + 'image:title' => new TranslatableMarkup('The image title'), 'image:caption' => "'The image & its \"caption.\"'", ], ]); diff --git a/xmlsitemap.install b/xmlsitemap.install index af6705661c0367916be7e21295a9ad55579f5d25..8bb46d67fb46879aaa3a4d0c31fb6ce9a0c634ee 100644 --- a/xmlsitemap.install +++ b/xmlsitemap.install @@ -10,6 +10,7 @@ use Drupal\Core\Language\LanguageInterface; use Drupal\Core\Session\AnonymousUserSession; use Drupal\Core\Url; +use Drupal\user\RoleInterface; /** * Implements hook_requirements(). @@ -173,7 +174,7 @@ function xmlsitemap_requirements($phase) { 'title' => $t('XML sitemap user'), 'value' => $t('Anonymous access to user profiles'), 'description' => $t('In order to list user profile links in the sitemap, the anonymous user must have the View user profiles permission.', [ - '@perm-link' => Url::fromRoute('entity.user_role.edit_permissions_form', ['user_role' => DRUPAL_ANONYMOUS_RID], ['fragment' => 'module-user'])->toString(), + '@perm-link' => Url::fromRoute('entity.user_role.edit_permissions_form', ['user_role' => RoleInterface::ANONYMOUS_ID], ['fragment' => 'module-user'])->toString(), ]), 'severity' => REQUIREMENT_ERROR, ]; diff --git a/xmlsitemap.module b/xmlsitemap.module index 06605edc2797329225d241fb2d74cf238b5a946f..2a41990192d5a7ac25421046ca77085471824cdc 100644 --- a/xmlsitemap.module +++ b/xmlsitemap.module @@ -1585,8 +1585,6 @@ function xmlsitemap_xmlsitemap_index_links($limit) { $chunks = array_chunk($ids, \Drupal::config('xmlsitemap.settings')->get('batch_limit')); foreach ($chunks as $chunk) { xmlsitemap_xmlsitemap_process_entity_links($entity_type_id, $chunk); - // Reset the entity cache afterwards to clear out some memory. - $entity_type_manager->getStorage($entity_type_id)->resetCache(); } } catch (\Exception $e) { @@ -1609,6 +1607,7 @@ function xmlsitemap_xmlsitemap_process_entity_links($entity_type_id, array $enti foreach ($entities as $entity) { xmlsitemap_xmlsitemap_process_entity_link($entity); } + // Reset the entity cache afterwards to clear out some memory. \Drupal::entityTypeManager()->getStorage($entity_type_id)->resetCache(); } diff --git a/xmlsitemap_custom/src/Controller/XmlSitemapCustomListController.php b/xmlsitemap_custom/src/Controller/XmlSitemapCustomListController.php index 3ecfafdf629187c5923716aca79f03de8c4aa47c..ee70dd10db3c592458a4c744e66b91f213b4baac 100644 --- a/xmlsitemap_custom/src/Controller/XmlSitemapCustomListController.php +++ b/xmlsitemap_custom/src/Controller/XmlSitemapCustomListController.php @@ -51,15 +51,30 @@ class XmlSitemapCustomListController extends ControllerBase { public function render() { $build['xmlsitemap_add_custom'] = [ '#type' => 'link', - '#title' => t('Add custom link'), + '#title' => $this->t('Add custom link'), '#href' => 'admin/config/search/xmlsitemap/custom/add', ]; $header = [ - 'loc' => ['data' => t('Location'), 'field' => 'loc', 'sort' => 'asc'], - 'priority' => ['data' => t('Priority'), 'field' => 'priority'], - 'changefreq' => ['data' => t('Change frequency'), 'field' => 'changefreq'], - 'language' => ['data' => t('Language'), 'field' => 'language'], - 'operations' => ['data' => t('Operations')], + 'loc' => [ + 'data' => $this->t('Location'), + 'field' => 'loc', + 'sort' => 'asc', + ], + 'priority' => [ + 'data' => $this->t('Priority'), + 'field' => 'priority', + ], + 'changefreq' => [ + 'data' => $this->t('Change frequency'), + 'field' => 'changefreq', + ], + 'language' => [ + 'data' => $this->t('Language'), + 'field' => 'language', + ], + 'operations' => [ + 'data' => $this->t('Operations'), + ], ]; $rows = []; @@ -76,16 +91,16 @@ class XmlSitemapCustomListController extends ControllerBase { $row = []; $row['loc'] = Link::fromTextAndUrl($link->loc, Url::fromUri('internal:' . $link->loc)); $row['priority'] = number_format($link->priority, 1); - $row['changefreq'] = $link->changefreq ? Unicode::ucfirst(xmlsitemap_get_changefreq($link->changefreq)) : t('None'); + $row['changefreq'] = $link->changefreq ? Unicode::ucfirst(xmlsitemap_get_changefreq($link->changefreq)) : $this->t('None'); if (isset($header['language'])) { $row['language'] = $language->getName(); } $operations['edit'] = [ - 'title' => t('Edit'), + 'title' => $this->t('Edit'), 'url' => Url::fromRoute('xmlsitemap_custom.edit', ['link' => $link->id]), ]; $operations['delete'] = [ - 'title' => t('Delete'), + 'title' => $this->t('Delete'), 'url' => Url::fromRoute('xmlsitemap_custom.delete', ['link' => $link->id]), ]; $row['operations'] = [