Commit 0f6c533e authored by gbyte.co's avatar gbyte.co

Merge branch '8.x-3.x' into 3017271-views-support

parents ee96b11e 7ff11255
#simple-sitemap-settings-form .progress__bar {
background-image: none;
}
......@@ -17,7 +17,7 @@
* @param array &$links
* Array containing multilingual links generated for each path to be indexed
*
* @param string|null $sitemap_variant
* @param string $sitemap_variant
*/
function hook_simple_sitemap_links_alter(array &$links, $sitemap_variant) {
......@@ -45,7 +45,7 @@ function hook_simple_sitemap_links_alter(array &$links, $sitemap_variant) {
* Add arbitrary links to the sitemap.
*
* @param array &$arbitrary_links
* @param string|null $sitemap_variant
* @param string $sitemap_variant
*/
function hook_simple_sitemap_arbitrary_links_alter(array &$arbitrary_links, $sitemap_variant) {
......@@ -85,7 +85,7 @@ function hook_simple_sitemap_arbitrary_links_alter(array &$arbitrary_links, $sit
* Attributes can be added, changed and removed.
*
* @param array &$attributes
* @param string|null $sitemap_variant
* @param string $sitemap_variant
*/
function hook_simple_sitemap_attributes_alter(array &$attributes, $sitemap_variant) {
......@@ -98,7 +98,7 @@ function hook_simple_sitemap_attributes_alter(array &$attributes, $sitemap_varia
* Attributes can be added, changed and removed.
*
* @param array &$index_attributes
* @param string|null $sitemap_variant
* @param string $sitemap_variant
*/
function hook_simple_sitemap_index_attributes_alter(array &$index_attributes, $sitemap_variant) {
......
......@@ -17,3 +17,8 @@ sitemapEntities:
dependencies:
- core/jquery
- core/drupalSettings
sitemapSettings:
version: VERSION
css:
theme:
css/simple_sitemap.settings.css: {}
......@@ -103,12 +103,12 @@ function simple_sitemap_entity_form_submit($form, FormStateInterface &$form_stat
/** @var \Drupal\simple_sitemap\Simplesitemap $generator */
$generator = \Drupal::service('simple_sitemap.generator');
$settings = [
'index' => (bool) $values['simple_sitemap_index_content'],
'priority' => $values['simple_sitemap_priority'],
'changefreq' => $values['simple_sitemap_changefreq'],
'include_images' => (bool) $values['simple_sitemap_include_images'],
];
// Only save other values if indexing is enabled.
if ($settings['index'] = (bool) $values['simple_sitemap_index_content']) {
$settings['priority'] = $values['simple_sitemap_priority'];
$settings['changefreq'] = $values['simple_sitemap_changefreq'];
$settings['include_images'] = (bool) $values['simple_sitemap_include_images'];
}
// Deleting bundle settings for old bundle.
// See SimplesitemapEntitiesForm::submitForm().
......
......@@ -43,17 +43,16 @@ class SimplesitemapController extends ControllerBase {
* or its sitemap index file.
* Caches the response in case of expected output, prevents caching otherwise.
*
* @param \Symfony\Component\HttpFoundation\Request $request
* The request object.
*
* @param string $variant
* Optional name of sitemap variant.
* @see \hook_simple_sitemap_variants_alter()
* @see SimplesitemapManager::getSitemapVariants()
*
* @param \Symfony\Component\HttpFoundation\Request $request
* The request object.
*
* @throws NotFoundHttpException
*
* @return object
* @return \Symfony\Component\HttpFoundation\Response|false
* Returns an XML response.
*/
public function getSitemap(Request $request, $variant = NULL) {
......@@ -63,13 +62,15 @@ class SimplesitemapController extends ControllerBase {
}
return new Response($output, Response::HTTP_OK, [
'content-type' => 'application/xml',
'X-Robots-Tag' => 'noindex', // Tell search engines not to index the sitemap itself.
'Content-type' => 'application/xml; charset=utf-8',
'X-Robots-Tag' => 'noindex, follow',
]);
}
/**
* Returns the XML stylesheet for the sitemap.
*
* @return \Symfony\Component\HttpFoundation\Response
*/
public function getSitemapXsl() {
......@@ -80,7 +81,7 @@ class SimplesitemapController extends ControllerBase {
// Replace custom tokens in the XSL content with appropriate values.
$replacements = [
'[title]' => $this->t('Sitemap file'),
'[generated-by]' => $this->t('Generated by the <a href="@link">Simple XML sitemap</a> Drupal module.', ['@link' => 'https://www.drupal.org/project/simple_sitemap']),
'[generated-by]' => $this->t('Generated by the <a href="@link">@module_name</a> Drupal module.', ['@link' => 'https://www.drupal.org/project/simple_sitemap', '@module_name' => 'Simple XML sitemap']),
'[number-of-sitemaps]' => $this->t('Number of sitemaps in this index'),
'[sitemap-url]' => $this->t('Sitemap URL'),
'[number-of-urls]' => $this->t('Number of URLs in this sitemap'),
......@@ -96,14 +97,12 @@ class SimplesitemapController extends ControllerBase {
'[xsl-js]' => base_path() . $module_path . '/xsl/simple_sitemap.xsl.js',
'[xsl-css]' => base_path() . $module_path . '/xsl/simple_sitemap.xsl.css',
];
$xsl_content = strtr($xsl_content, $replacements);
// Output the XSL content.
$response = new Response($xsl_content);
$response->headers->set('Content-type', 'application/xml; charset=utf-8');
$response->headers->set('X-Robots-Tag', 'noindex, follow');
return $response;
return new Response(strtr($xsl_content, $replacements), Response::HTTP_OK, [
'Content-type' => 'application/xml; charset=utf-8',
'X-Robots-Tag' => 'noindex, nofollow',
]);
}
}
......@@ -120,6 +120,7 @@ class FormHelper {
$this->cleanUpFormInfo();
$this->getEntityDataFromFormEntity();
$this->negotiateVariant();
return $this->supports();
}
......@@ -222,6 +223,7 @@ class FormHelper {
/**
* @param array $form_fragment
* @return $this
*/
public function displayRegenerateNow(&$form_fragment) {
$form_fragment['simple_sitemap_regenerate_now'] = [
......@@ -233,21 +235,30 @@ class FormHelper {
if ($this->generator->getSetting('cron_generate')) {
$form_fragment['simple_sitemap_regenerate_now']['#description'] .= '<br/>' . $this->t('Otherwise the sitemap will be regenerated during a future cron run.');
}
return $this;
}
protected function negotiateVariant() {
/**
* @return $this
*/
public function negotiateVariant() {
$all_bundle_settings = $this->generator->setVariants(TRUE)
->getBundleSettings($this->getEntityTypeId(), $this->getBundleName(), FALSE, TRUE);
$this->bundleSettings = NULL !== ($variant = key($all_bundle_settings))
? $all_bundle_settings[$variant]
: [];
$this->variant = $variant;
return $this;
}
/**
* @param array $form_fragment
* @param bool $multiple
* @return $this
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
*/
public function displayEntitySettings(&$form_fragment, $multiple = FALSE) {
$prefix = $multiple ? $this->getEntityTypeId() . '_' : '';
......@@ -288,7 +299,6 @@ class FormHelper {
function($variant) { return $this->t($variant['label']); },
$this->generator->getSitemapManager()->getSitemapVariants(NULL, FALSE)
),
'#default_value' => $this->variant,
'#states' => [
'visible' => !$multiple
? [':input[name="' . $prefix . 'simple_sitemap_index_content"]' => ['value' => 1]]
......@@ -299,6 +309,17 @@ class FormHelper {
],
'#disabled' => $this->getEntityCategory() === 'instance'
];
// If only one variant is available, set it, otherwise check if a default
// variant is provided and set it.
$form_fragment[$prefix . 'simple_sitemap_variant']['#default_value'] = NULL === $this->variant
? (1 === count($form_fragment[$prefix . 'simple_sitemap_variant']['#options'])
? array_keys($form_fragment[$prefix . 'simple_sitemap_variant']['#options'])[0]
: (!empty($default = $this->generator->getSetting('default_variant'))
? $default
: $this->variant
)
)
: $this->variant;
// Priority
$form_fragment[$prefix . 'simple_sitemap_priority'] = [
......@@ -436,14 +457,18 @@ class FormHelper {
*
* Needed because this service may contain form info from the previous
* operation when revived from the container.
*
* @return $this
*/
protected function cleanUpFormInfo() {
public function cleanUpFormInfo() {
$this->entityCategory = NULL;
$this->entityTypeId = NULL;
$this->bundleName = NULL;
$this->instanceId = NULL;
$this->variant = NULL;
$this->bundleSettings = NULL;
return $this;
}
/**
......@@ -474,6 +499,7 @@ class FormHelper {
return TRUE;
}
}
return FALSE;
}
......@@ -489,6 +515,7 @@ class FormHelper {
$value = $this->formatPriority($value / self::PRIORITY_DIVIDER);
$options[$value] = $value;
}
return $options;
}
......@@ -503,6 +530,7 @@ class FormHelper {
foreach (self::getChangefreqOptions() as $setting) {
$options[$setting] = $this->t($setting);
}
return $options;
}
......
......@@ -131,10 +131,17 @@ class SimplesitemapEntitiesForm extends SimplesitemapFormBase {
$form['#attached']['drupalSettings']['simple_sitemap']['all_entities'][] = $css_entity_type_id;
if ($atomic_entity_type) {
$this->formHelper->setEntityCategory('bundle')
$this->formHelper
->cleanUpFormInfo()
->setEntityCategory('bundle')
->setEntityTypeId($entity_type_id)
->setBundleName($entity_type_id)
->displayEntitySettings($form['simple_sitemap_entities']['entities'][$entity_type_id][$entity_type_id . '_settings'], TRUE);
->negotiateVariant()
->displayEntitySettings(
$form['simple_sitemap_entities']['entities'][$entity_type_id][$entity_type_id . '_settings'],
TRUE
);
$form['#attached']['drupalSettings']['simple_sitemap']['atomic_entities'][] = $css_entity_type_id;
}
}
......
......@@ -71,6 +71,8 @@ class SimplesitemapSettingsForm extends SimplesitemapFormBase {
public function buildForm(array $form, FormStateInterface $form_state) {
$form['simple_sitemap_settings']['#prefix'] = $this->getDonationText();
$form['simple_sitemap_settings']['#attached']['library'][] = 'simple_sitemap/sitemapSettings';
$queue_worker = $this->generator->getQueueWorker();
$form['simple_sitemap_settings']['status'] = [
'#type' => 'fieldset',
......@@ -84,24 +86,19 @@ class SimplesitemapSettingsForm extends SimplesitemapFormBase {
'#suffix' => '</div></div>',
];
$form['simple_sitemap_settings']['status']['actions']['regenerate_submit'] = [
$form['simple_sitemap_settings']['status']['actions']['rebuild_queue_submit'] = [
'#type' => 'submit',
'#value' => $this->t('Generate from queue'),
'#submit' => ['::generateSitemap'],
'#value' => $this->t('Rebuild queue'),
'#submit' => ['::rebuildQueue'],
'#validate' => [],
];
// $form['simple_sitemap_settings']['status']['actions']['regenerate_backend_submit'] = [
// '#type' => 'submit',
// '#value' => $this->t('Generate from queue (background)'),
// '#submit' => ['::generateSitemapBackend'],
// '#validate' => [],
// ];
$form['simple_sitemap_settings']['status']['actions']['rebuild_queue_submit'] = [
$form['simple_sitemap_settings']['status']['actions']['regenerate_submit'] = [
'#type' => 'submit',
'#value' => $this->t('Rebuild queue'),
'#submit' => ['::rebuildQueue'],
'#value' => $queue_worker->generationInProgress()
? $this->t('Resume generation')
: $this->t('Rebuild queue & generate'),
'#submit' => ['::generateSitemap'],
'#validate' => [],
];
......@@ -112,7 +109,6 @@ class SimplesitemapSettingsForm extends SimplesitemapFormBase {
$form['simple_sitemap_settings']['status']['progress']['title']['#markup'] = $this->t('Progress of sitemap regeneration');
$queue_worker = $this->generator->getQueueWorker();
$total_count = $queue_worker->getInitialElementCount();
if (!empty($total_count)) {
$indexed_count = $queue_worker->getProcessedElementCount();
......@@ -124,7 +120,7 @@ class SimplesitemapSettingsForm extends SimplesitemapFormBase {
$index_progress = [
'#theme' => 'progress_bar',
'#percent' => $percent,
'#message' => t('@indexed out of @total items have been processed.', ['@indexed' => $indexed_count, '@total' => $total_count]),
'#message' => $this->t('@indexed out of @total items have been processed.<br/>Each sitemap variant is published after all of its items have been processed.', ['@indexed' => $indexed_count, '@total' => $total_count]),
];
$form['simple_sitemap_settings']['status']['progress']['bar']['#markup'] = render($index_progress);
}
......@@ -355,7 +351,7 @@ class SimplesitemapSettingsForm extends SimplesitemapFormBase {
$base_url = $form_state->getValue('base_url');
$form_state->setValue('base_url', rtrim($base_url, '/'));
if ($base_url !== '' && !UrlHelper::isValid($base_url, TRUE)) {
$form_state->setErrorByName('base_url', t('The base URL is invalid.'));
$form_state->setErrorByName('base_url', $this->t('The base URL is invalid.'));
}
}
......@@ -393,16 +389,6 @@ class SimplesitemapSettingsForm extends SimplesitemapFormBase {
$this->generator->generateSitemap();
}
/**
* @param array $form
* @param \Drupal\Core\Form\FormStateInterface $form_state
* @throws \Drupal\Component\Plugin\Exception\PluginException
*/
public function generateSitemapBackend (array &$form, FormStateInterface $form_state) {
$this->generator->generateSitemap('backend');
}
/**
* @param array $form
* @param \Drupal\Core\Form\FormStateInterface $form_state
......
......@@ -25,7 +25,7 @@ trait BatchTrait {
'title' => $this->t('Generating XML sitemaps'),
'init_message' => $this->t('Initializing...'),
'error_message' => $this->t(self::$batchErrorMessage),
'progress_message' => $this->t('Processing items from queue. Each sitemap variant is published as soon as its items have been processed.'),
'progress_message' => $this->t('Processing items from the queue.<br/>Each sitemap variant is published after all of its items have been processed.'),
'operations' => [[ __CLASS__ . '::' . 'doBatchGenerateSitemap', []]],
'finished' => [__CLASS__, 'finishGeneration'],
];
......
......@@ -17,6 +17,7 @@ use Drupal\simple_sitemap\Plugin\simple_sitemap\SitemapGenerator\SitemapGenerato
* @package Drupal\simple_sitemap
*/
class Simplesitemap {
/**
* @var \Drupal\simple_sitemap\EntityHelper
*/
......@@ -165,6 +166,7 @@ class Simplesitemap {
*/
public function saveSetting($name, $setting) {
$this->settings->saveSetting($name, $setting);
return $this;
}
......@@ -193,7 +195,9 @@ class Simplesitemap {
*/
public function setVariants($variants = NULL) {
if (NULL === $variants) {
$this->variants = FALSE !== ($default_variant = $this->getSetting('default_variant')) ? [$default_variant] : [];
$this->variants = !empty($default_variant = $this->getSetting('default_variant', ''))
? [$default_variant]
: [];
}
elseif ($variants === TRUE) {
$this->variants = array_keys(
......@@ -268,15 +272,20 @@ class Simplesitemap {
* variant set the above keyed by sitemap delta.
*/
protected function fetchSitemapVariantInfo() {
$result = $this->db->select('simple_sitemap', 's')
->fields('s', ['id', 'delta', 'sitemap_created', 'type'])
->condition('s.status', 1)
->condition('s.type', $this->getVariants(), 'IN')
->execute();
return count($this->getVariants()) > 1
? $result->fetchAllAssoc('type')
: $result->fetchAllAssoc('delta');
if (!empty($this->getVariants())) {
$result = $this->db->select('simple_sitemap', 's')
->fields('s', ['id', 'delta', 'sitemap_created', 'type'])
->condition('s.status', 1)
->condition('s.type', $this->getVariants(), 'IN')
->execute();
return count($this->getVariants()) > 1
? $result->fetchAllAssoc('type')
: $result->fetchAllAssoc('delta');
}
else {
return [];
}
}
/**
......@@ -380,6 +389,7 @@ class Simplesitemap {
$enabled_entity_types[] = $entity_type_id;
$this->saveSetting('enabled_entity_types', $enabled_entity_types);
}
return $this;
}
......@@ -727,11 +737,11 @@ class Simplesitemap {
return unserialize($results);
}
else {
$entity = $this->entityTypeManager->getStorage($entity_type_id)
->load($id);
return $this->getBundleSettings(
$entity_type_id,
$this->entityHelper->getEntityInstanceBundleName($entity)
$this->entityHelper->getEntityInstanceBundleName(
$this->entityTypeManager->getStorage($entity_type_id)->load($id)
)
);
}
}
......@@ -782,6 +792,7 @@ class Simplesitemap {
*/
public function bundleIsIndexed($entity_type_id, $bundle_name = NULL) {
$settings = $this->getBundleSettings($entity_type_id, $bundle_name);
return !empty($settings['index']);
}
......
......@@ -110,7 +110,7 @@
<xsl:variable name="url_location">
<xsl:value-of select="sitemap:loc"/>
</xsl:variable>
<a href="{$url_location}" rel="nofollow">
<a href="{$url_location}">
<xsl:value-of select="$url_location"/>
</a>
</td>
......@@ -164,7 +164,7 @@
<xsl:value-of select="$url_language"/>
</dt>
<dd>
<a href="{$url_location}" rel="nofollow">
<a href="{$url_location}">
<xsl:value-of select="$url_location"/>
</a>
</dd>
......@@ -176,7 +176,7 @@
<xsl:value-of select="image:loc"/>
</xsl:variable>
<li>
<a href="{$image_location}" rel="nofollow">
<a href="{$image_location}">
<xsl:value-of select="$image_location"/>
</a>
</li>
......
......@@ -55,7 +55,7 @@
}
else {
// Options for sitemap table.
options.sortList = [[3, 1], [0, 0]];
options.sortList = [[3, 1]];
options.headers = {
2: {sorter: 'changefreq'},
4: {sorter: false },
......
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