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

Issue #2912994 by gbyte.co: Implement image indexation for custom links

parent f06aaddd
......@@ -5,6 +5,7 @@ remove_duplicates: true
skip_untranslated: false
batch_process_limit: 1500
base_url: ''
custom_links_include_images: false
enabled_entity_types:
- 'node'
- 'taxonomy_term'
......
......@@ -22,6 +22,9 @@ simple_sitemap.settings:
base_url:
label: 'Base URL'
type: string
custom_links_include_images:
label: 'Include images of custom links'
type: boolean
enabled_entity_types:
label: 'Enabled entity types'
type: sequence
......@@ -43,7 +46,7 @@ simple_sitemap.bundle_settings.*.*:
type: string
include_images:
label: 'Include images'
type: 'integer'
type: integer
simple_sitemap.custom:
label: 'Custom links'
......
......@@ -235,6 +235,6 @@ function simple_sitemap_delete_bundle_config($entity_type_id, $bundle) {
function simple_sitemap_robotstxt() {
return [
'# XML sitemap',
'Sitemap: ' . $GLOBALS['base_url'] . '/sitemap.xml',
'Sitemap: ' . $GLOBALS['base_url'] . '/sitemap.xml', //todo: Use base URL setting?
];
}
......@@ -7,13 +7,13 @@ use Drupal\Core\Url;
/**
* Class CustomUrlGenerator
* @package Drupal\simple_sitemap\Batch\Generator
*
* @todo Add image support
*/
class CustomUrlGenerator extends UrlGeneratorBase implements UrlGeneratorInterface {
const PATH_DOES_NOT_EXIST_OR_NO_ACCESS_MESSAGE = "The custom path @path has been omitted from the XML sitemap as it either does not exist, or it is not accessible to anonymous users. You can review custom paths <a href='@custom_paths_url'>here</a>.";
protected $includeImages;
/**
* Batch function which generates urls to custom paths.
*
......@@ -21,6 +21,8 @@ class CustomUrlGenerator extends UrlGeneratorBase implements UrlGeneratorInterfa
*/
public function generate($custom_paths) {
$this->includeImages = $this->generator->getSetting('custom_links_include_images', FALSE);
foreach ($this->getBatchIterationElements($custom_paths) as $i => $custom_path) {
$this->setCurrentId($i);
......@@ -49,6 +51,9 @@ class CustomUrlGenerator extends UrlGeneratorBase implements UrlGeneratorInterfa
? date_iso8601($entity->getChangedTime()) : NULL,
'priority' => isset($custom_path['priority']) ? $custom_path['priority'] : NULL,
'changefreq' => !empty($custom_path['changefreq']) ? $custom_path['changefreq'] : NULL,
'images' => $this->includeImages && method_exists($entity, 'getEntityTypeId')
? $this->getImages($entity->getEntityTypeId(), $entity->id())
: []
];
if (NULL !== $entity) {
$path_data['entity_info'] = [
......
......@@ -7,8 +7,6 @@ use Drupal\Core\Form\FormStateInterface;
/**
* Class SimplesitemapCustomLinksForm
* @package Drupal\simple_sitemap\Form
*
* @todo Add image support
*/
class SimplesitemapCustomLinksForm extends SimplesitemapFormBase {
......@@ -38,6 +36,14 @@ class SimplesitemapCustomLinksForm extends SimplesitemapFormBase {
'#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']['include_images'] = [
'#type' => 'select',
'#title' => $this->t('Include images'),
'#description' => $this->t('If a custom link points to an entity, include its referenced images in the sitemap.'),
'#default_value' => $this->generator->getSetting('custom_links_include_images', 0),
'#options' => [0 => $this->t('No'), 1 => $this->t('Yes')],
];
$this->formHelper->displayRegenerateNow($form['simple_sitemap_custom']);
return parent::buildForm($form, $form_state);
......@@ -90,6 +96,7 @@ class SimplesitemapCustomLinksForm extends SimplesitemapFormBase {
foreach ($custom_links as $link_config) {
$this->generator->addCustomLink($link_config['path'], $link_config);
}
$this->generator->saveSetting('custom_links_include_images', $form_state->getValue('include_images'));
parent::submitForm($form, $form_state);
// Regenerate sitemaps according to user setting.
......
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