Commit 345f5193 authored by Dave Reid's avatar Dave Reid Committed by Dave Reid

Issue #3042673 by Dave Reid: Fixed more coding standards and deprecated code.

parent 07522ee6
......@@ -45,7 +45,7 @@ class XmlSitemapForm extends EntityForm {
if (empty($visible_children)) {
$form['context']['empty'] = [
'#type' => 'markup',
'#markup' => '<p>' . t('There are currently no XML sitemap contexts available.') . '</p>',
'#markup' => '<p>' . $this->t('There are currently no XML sitemap contexts available.') . '</p>',
];
}
......
......@@ -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.'));
}
}
......
......@@ -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.<br />@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']}.<br/>" . var_export($link, TRUE), E_USER_ERROR);
}
if ($link['changecount'] < 0) {
trigger_error(t('Negative changecount value. Please report this to <a href="@516928">@516928</a>.<br />@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.<br/>" . 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.
......
......@@ -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')) {
......
......@@ -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.\"'",
],
]);
......
......@@ -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 <a href="@perm-link"><em>View user profiles</em> permission</a>.', [
'@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,
];
......
......@@ -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();
}
......
......@@ -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'] = [
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment