Commit f764181f authored by gbyte.co's avatar gbyte.co

Fix 8.x-3.x merge conflicts

parents de84092c bd32bd47
......@@ -25,7 +25,7 @@ content entity types including:
* ...
Contributed entity types like commerce products or media entities can be indexed
as well. On top of that custom links can be added to the sitemap.
as well. On top of that custom links and view pages can be added to the sitemap.
To learn about XML sitemaps, see https://en.wikipedia.org/wiki/Sitemaps.
......@@ -74,6 +74,13 @@ As the sitemaps are accessible to anonymous users, bear in mind that only links
will be included which are accessible to anonymous users. There are no access
checks for links added through the module's hooks (see below).
### VIEWS ###
To index views, enable the included, optional module Simple XML Sitemap (Views)
(simple_sitemap_views). Simple views as well as views with arguments can be
indexed on the view edit page. For views with arguments, links to all view
variants will be included in the sitemap.
### CUSTOM LINKS ###
To include custom links into a sitemap, visit
......@@ -93,7 +100,8 @@ configured under admin/config/search/simplesitemap/variants.
## USAGE ##
The sitemaps are accessible to the whole world under [variant name]/sitemap.xml.
In addition to that, the default sitemap is accessible under /sitemap.xml.
In addition to that, the default sitemap is accessible under /sitemap.xml. To
view the XML source, press ctrl+u.
If the cron generation is turned on, the sitemaps will be regenerated according
to the 'Sitemap generation interval' setting.
......
......@@ -20,7 +20,7 @@
else {
vals.push(Drupal.t('Excluded from sitemap'));
}
return vals.join('<br />');
return vals.join('<br>');
});
}
};
......
......@@ -112,7 +112,7 @@ function simple_sitemap_entity_form_submit($form, FormStateInterface &$form_stat
// Deleting bundle settings for old bundle.
// See SimplesitemapEntitiesForm::submitForm().
// todo: This will not be necessary if "multiple variants pro bundle" is implemented.
// todo: Not necessary once https://www.drupal.org/project/simple_sitemap/issues/3014649 is implemented.
if (isset($form['simple_sitemap']['simple_sitemap_variant']['#default_value'])) {
$old_variant = $form['simple_sitemap']['simple_sitemap_variant']['#default_value'];
if ($old_variant !== $values['simple_sitemap_variant']) {
......
......@@ -9,25 +9,33 @@ use Drupal\Core\Database\Connection;
use Drupal\Core\Url;
/**
* Class EntityHelper
* Helper class for working with entities.
*
* @package Drupal\simple_sitemap
*/
class EntityHelper {
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* The current active database's master connection.
*
* @var \Drupal\Core\Database\Connection
*/
protected $db;
/**
* EntityHelper constructor.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
* The entity type manager.
* @param \Drupal\Core\Database\Connection $database
* The current active database's master connection.
*/
public function __construct(EntityTypeManagerInterface $entityTypeManager, Connection $database) {
$this->entityTypeManager = $entityTypeManager;
......@@ -38,7 +46,10 @@ class EntityHelper {
* Gets an entity's bundle name.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity to get the bundle name for.
*
* @return string
* The bundle of the entity.
*/
public function getEntityInstanceBundleName(EntityInterface $entity) {
return $entity->getEntityTypeId() === 'menu_link_content'
......@@ -50,7 +61,10 @@ class EntityHelper {
* Gets the entity type id for a bundle.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity to get an entity type id for a bundle.
*
* @return null|string
* The entity type for a bundle or NULL on failure.
*/
public function getBundleEntityTypeId(EntityInterface $entity) {
return $entity->getEntityTypeId() === 'menu'
......@@ -82,7 +96,10 @@ class EntityHelper {
* Checks whether an entity type does not provide bundles.
*
* @param string $entity_type_id
* The entity type ID.
*
* @return bool
* TRUE if the entity type is atomic and FALSE otherwise.
*/
public function entityTypeIsAtomic($entity_type_id) {
......@@ -101,8 +118,14 @@ class EntityHelper {
}
/**
* Gets the entity from URL object.
*
* @param \Drupal\Core\Url $url_object
* The URL object.
*
* @return \Drupal\Core\Entity\EntityInterface|null
* An entity object. NULL if no matching entity is found.
*
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
*/
......@@ -116,9 +139,16 @@ class EntityHelper {
}
/**
* Gets the entity IDs by entity type and bundle.
*
* @param string $entity_type_id
* The entity type ID.
* @param string|null $bundle_name
* @return array|int
* The bundle name.
*
* @return array
* An array of entity IDs
*
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
*/
......@@ -142,9 +172,15 @@ class EntityHelper {
}
/**
* Gets a list of image URLs for specified entity ID.
*
* @param string $entity_type_name
* The name of the entity type in which the images are used.
* @param string $entity_id
* The ID of the entity.
*
* @return array
* An array containing the URLs of the images.
*/
public function getEntityImageUrls($entity_type_name, $entity_id) {
$query = $this->db->select('file_managed', 'fm');
......
......@@ -248,7 +248,7 @@ class FormHelper {
'#default_value' => FALSE,
];
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.');
$form_fragment['simple_sitemap_regenerate_now']['#description'] .= '<br>' . $this->t('Otherwise the sitemap will be regenerated during a future cron run.');
}
return $this;
......
......@@ -70,14 +70,14 @@ class SimplesitemapCustomLinksForm extends SimplesitemapFormBase {
'#type' => 'textarea',
'#title' => $this->t('Relative Drupal paths'),
'#default_value' => $this->customLinksToString($this->generator->setVariants(TRUE)->getCustomLinks(NULL, FALSE)),
'#description' => $this->t("Please specify drupal internal (relative) paths, one per line. Do not forget to prepend the paths with a '/'.<br/>Optionally link priority <em>(0.0 - 1.0)</em> can be added by appending it after a space.<br/> Optionally link change frequency <em>(always / hourly / daily / weekly / monthly / yearly / never)</em> can be added by appending it after a space.<br/><br/><strong>Examples:</strong><br/><em>/ 1.0 daily</em> -> home page with the highest priority and daily change frequency<br/><em>/contact</em> -> contact page with the default priority and no change frequency information"),
'#description' => $this->t("Please specify drupal internal (relative) paths, one per line. Do not forget to prepend the paths with a '/'.<br>Optionally link priority <em>(0.0 - 1.0)</em> can be added by appending it after a space.<br> Optionally link change frequency <em>(always / hourly / daily / weekly / monthly / yearly / never)</em> can be added by appending it after a space.<br/<br><strong>Examples:</strong><br><em>/ 1.0 daily</em> -> home page with the highest priority and daily change frequency<br><em>/contact</em> -> contact page with the default priority and no change frequency information"),
];
$form['simple_sitemap_custom']['variants'] = [
'#type' => 'select',
'#multiple' => TRUE,
'#title' => $this->t('Sitemap variants'),
'#description' => $this->t('The sitemap variants to include the above links in.<br/>Variants can be configured <a href="@url">here</a>.', ['@url' => $GLOBALS['base_url'] . '/admin/config/search/simplesitemap/variants']),
'#description' => $this->t('The sitemap variants to include the above links in.<br>Variants can be configured <a href="@url">here</a>.', ['@url' => $GLOBALS['base_url'] . '/admin/config/search/simplesitemap/variants']),
'#options' => array_map(
function($variant) { return $this->t($variant['label']); },
$this->generator->getSitemapManager()->getSitemapVariants(NULL, FALSE)
......
......@@ -165,7 +165,7 @@ class SimplesitemapEntitiesForm extends SimplesitemapFormBase {
// Deleting bundle settings for old bundle.
// See simple_sitemap.module::simple_sitemap_entity_form_submit().
// todo: This will not be necessary if "multiple variants pro bundle" is implemented.
// todo: Not necessary once https://www.drupal.org/project/simple_sitemap/issues/3014649 is implemented.
if (isset($form['simple_sitemap_entities']['entities'][$entity_type_id][$entity_type_id . '_settings'][$entity_type_id . '_simple_sitemap_variant']['#default_value'])) {
$old_variant = $form['simple_sitemap_entities']['entities'][$entity_type_id][$entity_type_id . '_settings'][$entity_type_id . '_simple_sitemap_variant']['#default_value'];
if ($old_variant !== $values[$entity_type_id . '_simple_sitemap_variant']) {
......
......@@ -120,7 +120,7 @@ class SimplesitemapSettingsForm extends SimplesitemapFormBase {
$index_progress = [
'#theme' => 'progress_bar',
'#percent' => $percent,
'#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]),
'#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);
}
......@@ -248,7 +248,7 @@ class SimplesitemapSettingsForm extends SimplesitemapFormBase {
$form['simple_sitemap_settings']['settings']['languages']['skip_untranslated'] = [
'#type' => 'checkbox',
'#title' => $this->t('Skip non-existent translations'),
'#description' => $this->t('If checked, entity links are generated exclusively for languages the entity has been translated to as long as the language is not excluded below.<br/>Otherwise entity links are generated for every language installed on the site apart from languages excluded below.<br/>Bear in mind that non-entity paths like homepage will always be generated for every non-excluded language.'),
'#description' => $this->t('If checked, entity links are generated exclusively for languages the entity has been translated to as long as the language is not excluded below.<br>Otherwise entity links are generated for every language installed on the site apart from languages excluded below.<br>Bear in mind that non-entity paths like homepage will always be generated for every non-excluded language.'),
'#default_value' => $this->generator->getSetting('skip_untranslated', FALSE),
];
......@@ -279,7 +279,7 @@ class SimplesitemapSettingsForm extends SimplesitemapFormBase {
$form['simple_sitemap_settings']['advanced']['default_variant'] = [
'#type' => 'select',
'#title' => $this->t('Default sitemap variant'),
'#description' => $this->t('This sitemap variant will be available under <em>/sitemap.xml</em> in addition to its default path <em>/variant-name/sitemap.xml</em>.<br/>Variants can be configured <a href="@url">here</a>.', ['@url' => $GLOBALS['base_url'] . '/admin/config/search/simplesitemap/variants']),
'#description' => $this->t('This sitemap variant will be available under <em>/sitemap.xml</em> in addition to its default path <em>/variant-name/sitemap.xml</em>.<br>Variants can be configured <a href="@url">here</a>.', ['@url' => $GLOBALS['base_url'] . '/admin/config/search/simplesitemap/variants']),
'#default_value' => isset($variants[$default_variant]) ? $default_variant : '',
'#options' => ['' => $this->t('- None -')] + array_map(function($variant) { return $this->t($variant['label']); }, $variants),
];
......@@ -289,13 +289,13 @@ class SimplesitemapSettingsForm extends SimplesitemapFormBase {
'#title' => $this->t('Default base URL'),
'#default_value' => $this->generator->getSetting('base_url', ''),
'#size' => 30,
'#description' => $this->t('On some hosting providers it is impossible to pass parameters to cron to tell Drupal which URL to bootstrap with. In this case the base URL of sitemap links can be overridden here.<br/>Example: <em>@url</em>', ['@url' => $GLOBALS['base_url']]),
'#description' => $this->t('On some hosting providers it is impossible to pass parameters to cron to tell Drupal which URL to bootstrap with. In this case the base URL of sitemap links can be overridden here.<br>Example: <em>@url</em>', ['@url' => $GLOBALS['base_url']]),
];
$form['simple_sitemap_settings']['advanced']['remove_duplicates'] = [
'#type' => 'checkbox',
'#title' => $this->t('Exclude duplicate links'),
'#description' => $this->t('Prevent per-sitemap variant duplicate links.<br/>Uncheck this to significantly speed up the sitemap generation process on a huge site (more than 20 000 indexed entities).'),
'#description' => $this->t('Prevent per-sitemap variant duplicate links.<br>Uncheck this to significantly speed up the sitemap generation process on a huge site (more than 20 000 indexed entities).'),
'#default_value' => $this->generator->getSetting('remove_duplicates', TRUE),
];
......@@ -303,7 +303,7 @@ class SimplesitemapSettingsForm extends SimplesitemapFormBase {
'#type' => 'number',
'#title' => $this->t('Maximum links in a sitemap'),
'#min' => 1,
'#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, but an equally important consideration is generation performance: Splitting sitemaps into chunks <em>greatly</em> increases it.<br/>If left blank, all links will be shown on a single 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, but an equally important consideration is generation performance: Splitting sitemaps into chunks <em>greatly</em> increases it.<br>If left blank, all links will be shown on a single sitemap.'),
'#default_value' => $this->generator->getSetting('max_links'),
];
......@@ -311,7 +311,7 @@ class SimplesitemapSettingsForm extends SimplesitemapFormBase {
'#type' => 'number',
'#title' => $this->t('Sitemap generation max duration'),
'#min' => 1,
'#description' => $this->t('The maximum duration <strong>in seconds</strong> the generation task can run during a single cron run or during one batch process iteration.<br/>The higher the number, the quicker the generation process, but higher the risk of PHP timeout errors.'),
'#description' => $this->t('The maximum duration <strong>in seconds</strong> the generation task can run during a single cron run or during one batch process iteration.<br>The higher the number, the quicker the generation process, but higher the risk of PHP timeout errors.'),
'#default_value' => $this->generator->getSetting('generate_duration', 10000) / 1000,
'#required' => TRUE,
];
......
......@@ -26,7 +26,7 @@ class SimplesitemapVariantsForm extends SimplesitemapFormBase {
$form['simple_sitemap_variants'] = [
'#title' => $this->t('Sitemap variants'),
'#type' => 'fieldset',
'#markup' => '<div class="description">' . $this->t('Define sitemap variants. A sitemap variant is a sitemap instance of a certain type (specific sitemap generator and URL generators) accessible under a certain URL.<br/>Each variant can have its own entity bundle settings (to be defined on bundle edit pages).') . '</div>',
'#markup' => '<div class="description">' . $this->t('Define sitemap variants. A sitemap variant is a sitemap instance of a certain type (specific sitemap generator and URL generators) accessible under a certain URL.<br>Each variant can have its own entity bundle settings (to be defined on bundle edit pages).') . '</div>',
'#prefix' => $this->getDonationText(),
];
......@@ -34,11 +34,11 @@ class SimplesitemapVariantsForm extends SimplesitemapFormBase {
'#type' => 'textarea',
'#title' => $this->t('Variants'),
'#default_value' => $this->variantsToString($this->generator->getSitemapManager()->getSitemapVariants(NULL, TRUE)),
'#description' => $this->t("Please specify sitemap variants, one per line. <strong>Caution: </strong>Removing variants here will delete their bundle settings, custom links and corresponding sitemap instances.<br/><br/>A variant definition consists of the variant name (used as the variant's path), the sitemap type it belongs to (optional) and the variant label (optional). These three values have to be separated by the | pipe | symbol.<br/><br/><strong>Examples:</strong><br/><em>default | default_hreflang | Default</em> -> variant of the <em>default_hreflang</em> sitemap type and <em>Default</em> as label; accessible under <em>/default/sitemap.xml</em><br/><em>test</em> -> variant of the <em>@default_sitemap_type</em> sitemap type and <em>test</em> as label; accessible under <em>/test/sitemap.xml</em><br/><br/><strong>Available sitemap types:</strong>", ['@default_sitemap_type' => SimplesitemapManager::DEFAULT_SITEMAP_TYPE]),
'#description' => $this->t("Please specify sitemap variants, one per line. <strong>Caution: </strong>Removing variants here will delete their bundle settings, custom links and corresponding sitemap instances.<br><br>A variant definition consists of the variant name (used as the variant's path), the sitemap type it belongs to (optional) and the variant label (optional). These three values have to be separated by the | pipe | symbol.<br><br><strong>Examples:</strong><br><em>default | default_hreflang | Default</em> -> variant of the <em>default_hreflang</em> sitemap type and <em>Default</em> as label; accessible under <em>/default/sitemap.xml</em><br><em>test</em> -> variant of the <em>@default_sitemap_type</em> sitemap type and <em>test</em> as label; accessible under <em>/test/sitemap.xml</em><br><br><strong>Available sitemap types:</strong>", ['@default_sitemap_type' => SimplesitemapManager::DEFAULT_SITEMAP_TYPE]),
];
foreach ($this->generator->getSitemapManager()->getSitemapTypes() as $sitemap_type => $definition) {
$form['simple_sitemap_variants']['variants']['#description'] .= '<br/>' . '<em>' . $sitemap_type . '</em>' . (!empty($definition['description']) ? (': ' . $definition['description']) : '');
$form['simple_sitemap_variants']['variants']['#description'] .= '<br>' . '<em>' . $sitemap_type . '</em>' . (!empty($definition['description']) ? (': ' . $definition['description']) : '');
}
$this->formHelper->displayRegenerateNow($form['simple_sitemap_custom']);
......
......@@ -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 the queue.<br/>Each sitemap variant is published after all of 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'],
];
......@@ -55,7 +55,6 @@ trait BatchTrait {
* @param $context
* @throws \Drupal\Component\Plugin\Exception\PluginException
*
* @todo Make sure batch does not run at the same time as cron.
* @todo Variants into generateSitemap().
*/
public static function doBatchGenerateSitemap(&$context) {
......
......@@ -439,7 +439,6 @@ class Simplesitemap {
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
*
* @todo: enableEntityType automatically
* @todo multiple variants
*/
public function setBundleSettings($entity_type_id, $bundle_name = NULL, $settings = ['index' => TRUE]) {
......
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