Commit aad5328d authored by Nitesh Pawar's avatar Nitesh Pawar Committed by gbyte.co

Issue #2762419 by Nitesh Pawar: Replaced t() with $this->t()

parent c2804520
......@@ -13,8 +13,10 @@ use Drupal\user\Entity\User;
use Drupal\Core\Url;
use Drupal\Component\Utility\Html;
use Drupal\Core\Cache\Cache;
use Drupal\Core\StringTranslation\StringTranslationTrait;
class Batch {
use StringTranslationTrait;
private $batch;
private $batchInfo;
......@@ -27,10 +29,10 @@ class Batch {
function __construct() {
$this->batch = [
'title' => t('Generating XML sitemap'),
'init_message' => t(self::BATCH_INIT_MESSAGE),
'error_message' => t(self::BATCH_ERROR_MESSAGE),
'progress_message' => t(self::BATCH_PROGRESS_MESSAGE),
'title' => $this->t('Generating XML sitemap'),
'init_message' => $this->t(self::BATCH_INIT_MESSAGE),
'error_message' => $this->t(self::BATCH_ERROR_MESSAGE),
'progress_message' => $this->t(self::BATCH_PROGRESS_MESSAGE),
'operations' => [],
'finished' => [__CLASS__, 'finishGeneration'], // __CLASS__ . '::finishGeneration' not working possibly due to a drush error.
];
......
......@@ -6,11 +6,13 @@
namespace Drupal\simple_sitemap;
use Drupal\Core\StringTranslation\StringTranslationTrait;
/**
* Form class.
*/
class Form {
use StringTranslationTrait;
const PRIORITY_DEFAULT = 0.5;
const PRIORITY_HIGHEST = 10;
const PRIORITY_DIVIDER = 10;
......@@ -83,12 +85,12 @@ class Form {
public function displayRegenerateNow(&$form_fragment) {
$form_fragment['simple_sitemap_regenerate_now'] = [
'#type' => 'checkbox',
'#title' => t('Regenerate sitemap after hitting <em>Save</em>'),
'#description' => t('This setting will regenerate the whole sitemap including the above changes.'),
'#title' => $this->t('Regenerate sitemap after hitting <em>Save</em>'),
'#description' => $this->t('This setting will regenerate the whole sitemap including the above changes.'),
'#default_value' => FALSE,
];
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>' . $this->t('Otherwise the sitemap will be regenerated on the next cron run.');
}
}
......@@ -104,35 +106,35 @@ class Form {
}
$index = isset($settings['index']) ? $settings['index'] : 0;
$priority = isset($settings['priority']) ? $settings['priority'] : self::PRIORITY_DEFAULT;
$bundle_name = !empty($this->bundleName) ? $this->bundleName : t('undefined');
$bundle_name = !empty($this->bundleName) ? $this->bundleName : $this->t('undefined');
if (!$multiple) {
$form_fragment[$prefix . 'simple_sitemap_index_content'] = [
'#type' => 'radios',
'#default_value' => $index,
'#options' => [
0 => $this->entityCategory == 'instance' ? t('Do not index this @bundle entity', ['@bundle' => $bundle_name]) : t('Do not index entities of this type'),
1 => $this->entityCategory == 'instance' ? t('Index this @bundle entity', ['@bundle' => $bundle_name]) : t('Index entities of this type'),
0 => $this->entityCategory == 'instance' ? $this->t('Do not index this @bundle entity', ['@bundle' => $bundle_name]) : $this->t('Do not index entities of this type'),
1 => $this->entityCategory == 'instance' ? $this->t('Index this @bundle entity', ['@bundle' => $bundle_name]) : $this->t('Index entities of this type'),
]
];
if ($this->entityCategory == 'instance' && isset($bundle_settings['index'])) {
$form_fragment[$prefix . 'simple_sitemap_index_content']['#options'][$bundle_settings['index']] .= ' <em>(' . t('Default') . ')</em>';
$form_fragment[$prefix . 'simple_sitemap_index_content']['#options'][$bundle_settings['index']] .= ' <em>(' . $this->t('Default') . ')</em>';
}
}
if ($this->entityCategory == 'instance')
$priority_description = t('The priority this @bundle entity will have in the eyes of search engine bots.', ['@bundle' => $bundle_name]);
$priority_description = $this->t('The priority this @bundle entity will have in the eyes of search engine bots.', ['@bundle' => $bundle_name]);
else
$priority_description = t('The priority entities of this type will have in the eyes of search engine bots.');
$priority_description = $this->t('The priority entities of this type will have in the eyes of search engine bots.');
$form_fragment[$prefix . 'simple_sitemap_priority'] = [
'#type' => 'select',
'#title' => t('Priority'),
'#title' => $this->t('Priority'),
'#description' => $priority_description,
'#default_value' => $priority,
'#options' => self::getPrioritySelectValues(),
];
if ($this->entityCategory == 'instance' && isset($bundle_settings['priority'])) {
$form_fragment[$prefix . 'simple_sitemap_priority']['#options'][(string)$bundle_settings['priority']] .= ' (' . t('Default') . ')';
$form_fragment[$prefix . 'simple_sitemap_priority']['#options'][(string)$bundle_settings['priority']] .= ' (' . $this->t('Default') . ')';
}
}
......
......@@ -45,16 +45,16 @@ class SimplesitemapCustomLinksForm extends ConfigFormBase {
}
$form['simple_sitemap_custom'] = [
'#title' => t('Custom links'),
'#title' => $this->t('Custom links'),
'#type' => 'fieldset',
'#markup' => '<p>' . t('Add custom internal drupal paths to the XML sitemap.') . '</p>',
'#markup' => '<p>' . $this->t('Add custom internal drupal paths to the XML sitemap.') . '</p>',
];
$form['simple_sitemap_custom']['custom_links'] = [
'#type' => 'textarea',
'#title' => t('Relative Drupal paths'),
'#title' => $this->t('Relative Drupal paths'),
'#default_value' => $setting_string,
'#description' => t("Please specify drupal internal (relative) paths, one per line. Do not forget to prepend the paths with a '/'. You can optionally add a priority (0.0 - 1.0) by appending it to the path after a space. The home page with the highest priority would be <em>/ 1.0</em>, the contact page with the default priority would be <em>/contact 0.5</em>."),
'#description' => $this->t("Please specify drupal internal (relative) paths, one per line. Do not forget to prepend the paths with a '/'. You can optionally add a priority (0.0 - 1.0) by appending it to the path after a space. The home page with the highest priority would be <em>/ 1.0</em>, the contact page with the default priority would be <em>/contact 0.5</em>."),
];
$f = new Form();
......@@ -73,14 +73,14 @@ class SimplesitemapCustomLinksForm extends ConfigFormBase {
foreach($custom_link_config as $link_config) {
if (!\Drupal::service('path.validator')->isValid($link_config['path'])) {
$form_state->setErrorByName('', t("The path <em>@path</em> does not exist.", ['@path' => $link_config['path']]));
$form_state->setErrorByName('', $this->t("The path <em>@path</em> does not exist.", ['@path' => $link_config['path']]));
}
if ($link_config['path'][0] != '/') {
$form_state->setErrorByName('', t("The path <em>@path</em> needs to start with a '/'.", ['@path' => $link_config['path']]));
$form_state->setErrorByName('', $this->t("The path <em>@path</em> needs to start with a '/'.", ['@path' => $link_config['path']]));
}
if (isset($link_config['priority'])) {
if (!Form::isValidPriority($link_config['priority'])) {
$form_state->setErrorByName('', t("The priority setting <em>@priority</em> for path <em>@path</em> is incorrect. Set the priority from 0.0 to 1.0.", ['@priority' => $link_config['priority'], '@path' => $link_config['path']]));
$form_state->setErrorByName('', $this->t("The priority setting <em>@priority</em> for path <em>@path</em> is incorrect. Set the priority from 0.0 to 1.0.", ['@priority' => $link_config['priority'], '@path' => $link_config['path']]));
}
}
}
......
......@@ -39,9 +39,9 @@ class SimplesitemapEntitiesForm extends ConfigFormBase {
$generator = \Drupal::service('simple_sitemap.generator');
$form['simple_sitemap_entities']['entities'] = [
'#title' => t('Sitemap entities'),
'#title' => $this->t('Sitemap entities'),
'#type' => 'fieldset',
'#markup' => '<p>' . 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';
......@@ -63,13 +63,13 @@ class SimplesitemapEntitiesForm extends ConfigFormBase {
];
$form['simple_sitemap_entities']['entities'][$entity_type_id][$entity_type_id . '_enabled'] = [
'#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]),
'#description' => t('Sitemap settings for this entity type can be set on its bundle pages and overridden on its entity pages.'),
'#title' => $this->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' => $this->t('Sitemap settings for this entity type can be set on its bundle pages and overridden on its entity pages.'),
'#default_value' => $generator->entityTypeIsEnabled($entity_type_id),
];
$form['#attached']['drupalSettings']['simple_sitemap']['all_entities'][] = str_replace('_', '-', $entity_type_id);
if (Simplesitemap::entityTypeIsAtomic($entity_type_id)) {
$form['simple_sitemap_entities']['entities'][$entity_type_id][$entity_type_id . '_enabled']['#description'] = t('Sitemap settings for this entity type can be set below and overridden on its entity pages.');
$form['simple_sitemap_entities']['entities'][$entity_type_id][$entity_type_id . '_enabled']['#description'] = $this->t('Sitemap settings for this entity type can be set below and overridden on its entity pages.');
$f->setEntityCategory('bundle');
$f->setEntityTypeId($entity_type_id);
$f->setBundleName($entity_type_id);
......
......@@ -41,45 +41,45 @@ class SimplesitemapSettingsForm extends ConfigFormBase {
$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']['regenerate'] = [
'#title' => t('Regenerate sitemap'),
'#title' => $this->t('Regenerate sitemap'),
'#type' => 'fieldset',
'#markup' => '<p>' . t('This will regenerate the XML sitemap for all languages.') . '</p>',
'#markup' => '<p>' . $this->t('This will regenerate the XML sitemap for all languages.') . '</p>',
];
$form['simple_sitemap_settings']['regenerate']['regenerate_submit'] = [
'#type' => 'submit',
'#value' => t('Regenerate sitemap'),
'#value' => $this->t('Regenerate sitemap'),
'#submit' => ['::generateSitemap'],
'#validate' => [], // Skip form-level validator.
];
$form['simple_sitemap_settings']['settings'] = [
'#title' => t('Settings'),
'#title' => $this->t('Settings'),
'#type' => 'fieldset',
];
$form['simple_sitemap_settings']['settings']['cron_generate'] = [
'#type' => 'checkbox',
'#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.'),
'#title' => $this->t('Regenerate the sitemap on every cron run'),
'#description' => $this->t('Uncheck this if you intend to only regenerate the sitemap manually or via drush.'),
'#default_value' => $generator->getSetting('cron_generate'),
];
$form['simple_sitemap_settings']['advanced'] = [
'#title' => t('Advanced settings'),
'#title' => $this->t('Advanced settings'),
'#type' => 'details',
];
$form['simple_sitemap_settings']['advanced']['remove_duplicates'] = [
'#type' => 'checkbox',
'#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).'),
'#title' => $this->t('Exclude duplicate links'),
'#description' => $this->t('Uncheck this to significantly speed up the sitemap generation process on a huge site (more than 20 000 indexed entities).'),
'#default_value' => $generator->getSetting('remove_duplicates'),
];
$form['simple_sitemap_settings']['advanced']['max_links'] = [
'#title' => t('Maximum links in a sitemap'),
'#description' => 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."),
'#title' => $this->t('Maximum links in a 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."),
'#type' => 'textfield',
'#maxlength' => 5,
'#size' => 5,
......@@ -87,8 +87,8 @@ class SimplesitemapSettingsForm extends ConfigFormBase {
];
$form['simple_sitemap_settings']['advanced']['batch_process_limit'] = [
'#title' => t('Refresh batch every n links'),
'#description' => t("During sitemap generation, the batch process will issue a page refresh after n links processed to prevent PHP timeouts and memory exhaustion. 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."),
'#title' => $this->t('Refresh batch every n links'),
'#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. 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."),
'#type' => 'textfield',
'#maxlength' => 5,
'#size' => 5,
......@@ -105,13 +105,13 @@ class SimplesitemapSettingsForm extends ConfigFormBase {
$max_links = $form_state->getValue('max_links');
if ($max_links != '') {
if (!is_numeric($max_links) || $max_links < 1 || $max_links != round($max_links)) {
$form_state->setErrorByName('', t("The value of the <em>Maximum links in a sitemap</em> field must be empty, or a positive integer greater than 0."));
$form_state->setErrorByName('', $this->t("The value of the <em>Maximum links in a sitemap</em> field must be empty, or a positive integer greater than 0."));
}
}
$batch_process_limit = $form_state->getValue('batch_process_limit');
if (!is_numeric($batch_process_limit) || $batch_process_limit < 1 || $batch_process_limit != round($batch_process_limit)) {
$form_state->setErrorByName('', t("The value of the <em>Refresh batch every n links</em> field must be a positive integer greater than 0."));
$form_state->setErrorByName('', $this->t("The value of the <em>Refresh batch every n links</em> field must be a positive integer greater than 0."));
}
}
......
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