Commit 1c2cdead authored by gbyte.co's avatar gbyte.co

Clean up some

parent 067530c4
......@@ -110,9 +110,16 @@ Altering sitemap attributes and sitemap index attributes is possible through the
use of hook_simple_sitemap_attributes_alter(&$attributes){} and
hook_simple_sitemap_index_attributes_alter(&$index_attributes){}.
Adding new URL generator plugins and altering existing ones is possible through
Altering URL generator plugins is possible through
the use of hook_simple_sitemap_url_generators_alter(&$generators){}.
In case this module's URL generators do not cover your use case, it is possible
to implement new generator plugins in a custom module. To do it, simply extend
the Drupal\simple_sitemap\Plugin\simple_sitemap\UrlGenerator\UrlGeneratorBase
class. See the generator plugins included in this module and check the API docs
(https://www.drupal.org/docs/8/api/plugin-api/plugin-api-overview) to learn how
to implement plugins.
There are API methods for altering stored inclusion settings, status queries and
programmatic sitemap generation. These include:
......
......@@ -18,7 +18,7 @@ function simple_sitemap_requirements($phase) {
$requirements['simple_sitemap_php_extensions'] = [
'title' => t('Simple XML sitemap PHP extensions'),
'value' => t('Missing PHP xmlwriter extension'),
'description' => t("In order to be able to generate sitemaps, the Simple XML sitemap module requires the <em>xmlwriter</em> PHP extension to be enabled."),
'description' => t('In order to be able to generate sitemaps, the Simple XML sitemap module requires the <em>xmlwriter</em> PHP extension to be enabled.'),
'severity' => REQUIREMENT_ERROR,
];
}
......@@ -34,8 +34,8 @@ function simple_sitemap_requirements($phase) {
if (!$generated_ago) {
$value = t('Not available');
$description = t($cron_generation
? "Run cron, or <a href='@generate'>generate</a> the sitemap manually."
: "Generation on cron run is disabled. <a href='@generate'>Generate</a> the sitemap manually.", [
? 'Run cron, or <a href="@generate">generate</a> the sitemap manually.'
: 'Generation on cron run is disabled. <a href="@generate">Generate</a> the sitemap manually.', [
'@generate' => $GLOBALS['base_url'] . '/admin/config/search/simplesitemap'
]
);
......@@ -43,10 +43,10 @@ function simple_sitemap_requirements($phase) {
}
else {
$value = t('XML sitemap is available');
$description = t("The <a href='@sitemap'>XML sitemap</a> was generated @ago ago."
$description = t('The <a href="@sitemap">XML sitemap</a> was generated @ago ago.'
. ' ' . ($cron_generation
? "Run cron, or <a href='@generate'>regenerate</a> the sitemap manually."
: "Generation on cron run is disabled. <a href='@generate'>Regenerate</a> the sitemap manually."), [
? 'Run cron, or <a href="@generate">regenerate</a> the sitemap manually.'
: 'Generation on cron run is disabled. <a href="@generate">Regenerate</a> the sitemap manually.'), [
'@sitemap' => $GLOBALS['base_url'] . '/sitemap.xml',
'@ago' => $generated_ago,
'@generate' => $GLOBALS['base_url'] . '/admin/config/search/simplesitemap'
......@@ -307,7 +307,7 @@ function simple_sitemap_update_8206() {
unset($custom_links[$i]);
}
}
\Drupal::service('config.factory')->getEditable("simple_sitemap.custom")
\Drupal::service('config.factory')->getEditable('simple_sitemap.custom')
->setData(['links' => $custom_links])->save();
}
......
......@@ -46,12 +46,12 @@ function simple_sitemap_form_alter(&$form, FormStateInterface $form_state, $form
'#type' => 'details',
'#group' => isset($form['additional_settings']) ? 'additional_settings' : 'advanced',
'#title' => t('Simple XML sitemap'),
'#description' => $f->getEntityCategory() == 'instance' ? t('Settings for this entity can be overridden here.') : '',
'#description' => $f->getEntityCategory() === 'instance' ? t('Settings for this entity can be overridden here.') : '',
];
// Attach some js magic to forms.
// todo: JS not working on comment entity form, hence disabling.
if ($f->getEntityTypeId() != 'comment' || $f->getEntityCategory() != 'instance') {
if ($f->getEntityTypeId() !== 'comment' || $f->getEntityCategory() !== 'instance') {
$form['#attached']['library'][] = 'simple_sitemap/form';
}
......@@ -67,7 +67,7 @@ function simple_sitemap_form_alter(&$form, FormStateInterface $form_state, $form
// Add submission handler.
if (isset($form['actions']['submit']['#submit'])) {
foreach (array_keys($form['actions']) as $action) {
if ($action != 'preview'
if ($action !== 'preview'
&& isset($form['actions'][$action]['#type'])
&& $form['actions'][$action]['#type'] === 'submit') {
$form['actions'][$action]['#submit'][] = 'simple_sitemap_entity_form_submit';
......@@ -240,7 +240,7 @@ function simple_sitemap_delete_bundle_config($entity_type_id, $bundle) {
// Delete bundle settings.
\Drupal::service('config.factory')->getEditable("simple_sitemap.bundle_settings.$entity_type_id.$bundle")->delete();
$message = "You may want to <a href='@url'>regenerate</a> your XML sitemap now.";
$message = 'You may want to <a href="@url">regenerate</a> your XML sitemap now.';
if ($generator->getSetting('cron_generate')) {
$message .= ' Otherwise the sitemap will be regenerated during a future cron run.';
}
......
......@@ -3,6 +3,7 @@
namespace Drupal\simple_sitemap;
use Drupal\Core\Entity\ContentEntityTypeInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Database\Connection;
use Drupal\Core\Entity\Entity;
......@@ -37,10 +38,10 @@ class EntityHelper {
/**
* Gets an entity's bundle name.
*
* @param \Drupal\Core\Entity\Entity $entity
* @param \Drupal\Core\Entity\EntityInterface $entity
* @return string
*/
public function getEntityInstanceBundleName(Entity $entity) {
public function getEntityInstanceBundleName(EntityInterface $entity) {
return $entity->getEntityTypeId() == 'menu_link_content'
// Menu fix.
? $entity->getMenuName() : $entity->bundle();
......@@ -49,10 +50,10 @@ class EntityHelper {
/**
* Gets the entity type id for a bundle.
*
* @param \Drupal\Core\Entity\Entity $entity
* @param \Drupal\Core\Entity\EntityInterface $entity
* @return null|string
*/
public function getBundleEntityTypeId(Entity $entity) {
public function getBundleEntityTypeId(EntityInterface $entity) {
return $entity->getEntityTypeId() == 'menu'
// Menu fix.
? 'menu_link_content' : $entity->getEntityType()->getBundleOf();
......
......@@ -230,38 +230,45 @@ class FormHelper {
if ($this->getEntityCategory() === 'instance') {
$bundle_settings = $this->generator->getBundleSettings($this->getEntityTypeId(), $this->getBundleName());
$settings = NULL !== $this->getInstanceId() ? $this->generator->getEntityInstanceSettings($this->getEntityTypeId(), $this->getInstanceId()) : $bundle_settings;
$settings = NULL !== $this->getInstanceId()
? $this->generator->getEntityInstanceSettings($this->getEntityTypeId(), $this->getInstanceId())
: $bundle_settings;
}
else {
$settings = $this->generator->getBundleSettings($this->getEntityTypeId(), $this->getBundleName());
}
$index = isset($settings['index']) ? $settings['index'] : 0;
$priority = isset($settings['priority']) ? $settings['priority'] : self::PRIORITY_DEFAULT;
$changefreq = !empty($settings['changefreq']) ? $settings['changefreq'] : '';
$include_images = !empty($settings['include_images']) ? $settings['include_images'] : 0;
Simplesitemap::supplementDefaultSettings('entity', $settings, ['index' => 0]);
$bundle_name = !empty($this->getBundleName()) ? $this->getBundleName() : $this->t('undefined');
// Index
if (!$multiple) {
$form_fragment[$prefix . 'simple_sitemap_index_content'] = [
'#type' => 'radios',
'#default_value' => $index,
'#default_value' => $settings['index'],
'#options' => [
0 => $this->getEntityCategory() === 'instance' ? $this->t('Do not index this @bundle entity', ['@bundle' => $bundle_name]) : $this->t('Do not index entities of this type'),
1 => $this->getEntityCategory() === 'instance' ? $this->t('Index this @bundle entity', ['@bundle' => $bundle_name]) : $this->t('Index entities of this type'),
0 => $this->getEntityCategory() === 'instance'
? $this->t('Do not index this @bundle entity', ['@bundle' => $bundle_name])
: $this->t('Do not index entities of this type'),
1 => $this->getEntityCategory() === 'instance'
? $this->t('Index this @bundle entity', ['@bundle' => $bundle_name])
: $this->t('Index entities of this type'),
],
];
if ($this->getEntityCategory() === 'instance' && isset($bundle_settings['index'])) {
$form_fragment[$prefix . 'simple_sitemap_index_content']['#options'][$bundle_settings['index']] .= ' <em>(' . $this->t('default') . ')</em>';
}
}
// Priority
$form_fragment[$prefix . 'simple_sitemap_priority'] = [
'#type' => 'select',
'#title' => $this->t('Priority'),
'#description' => $this->getEntityCategory() === 'instance'
? $this->t('The priority this @bundle entity will have in the eyes of search engine bots.', ['@bundle' => $bundle_name])
: $this->t('The priority entities of this type will have in the eyes of search engine bots.'),
'#default_value' => $priority,
'#default_value' => $settings['priority'],
'#options' => $this->getPrioritySelectValues(),
];
......@@ -269,13 +276,14 @@ class FormHelper {
$form_fragment[$prefix . 'simple_sitemap_priority']['#options'][$this->formatPriority($bundle_settings['priority'])] .= ' (' . $this->t('default') . ')';
}
// Changefreq
$form_fragment[$prefix . 'simple_sitemap_changefreq'] = [
'#type' => 'select',
'#title' => $this->t('Change frequency'),
'#description' => $this->getEntityCategory() === 'instance'
? $this->t('The frequency with which this @bundle entity changes. Search engine bots may take this as an indication of how often to index it.', ['@bundle' => $bundle_name])
: $this->t('The frequency with which entities of this type change. Search engine bots may take this as an indication of how often to index them.'),
'#default_value' => $changefreq,
'#default_value' => $settings['changefreq'],
'#options' => $this->getChangefreqSelectValues(),
];
......@@ -283,13 +291,14 @@ class FormHelper {
$form_fragment[$prefix . 'simple_sitemap_changefreq']['#options'][$bundle_settings['changefreq']] .= ' (' . $this->t('default') . ')';
}
// Images
$form_fragment[$prefix . 'simple_sitemap_include_images'] = [
'#type' => 'select',
'#title' => $this->t('Include images'),
'#description' => $this->getEntityCategory() === 'instance'
? $this->t('Determines if images referenced by this @bundle entity should be included in the sitemap.', ['@bundle' => $bundle_name])
: $this->t('Determines if images referenced by entities of this type should be included in the sitemap.'),
'#default_value' => $include_images,
'#default_value' => $settings['include_images'],
'#options' => [0 => $this->t('No'), 1 => $this->t('Yes')],
];
......@@ -308,48 +317,48 @@ class FormHelper {
* TRUE if this is a bundle or bundle instance form, FALSE otherwise.
*/
protected function getEntityDataFromFormEntity() {
$form_entity = $this->getFormEntity();
if ($form_entity !== FALSE) {
$entity_type_id = $form_entity->getEntityTypeId();
$sitemap_entity_types = $this->entityHelper->getSupportedEntityTypes();
if (isset($sitemap_entity_types[$entity_type_id])) {
$this->setEntityCategory('instance');
}
else {
/**
* @var \Drupal\Core\Entity\EntityType $sitemap_entity_type
*/
foreach ($sitemap_entity_types as $sitemap_entity_type) {
if ($sitemap_entity_type->getBundleEntityType() == $entity_type_id) {
$this->setEntityCategory('bundle');
break;
}
}
}
// Menu fix.
$this->setEntityCategory(NULL === $this->getEntityCategory() && $entity_type_id == 'menu' ? 'bundle' : $this->getEntityCategory());
switch ($this->getEntityCategory()) {
case 'bundle':
$this->setEntityTypeId($this->entityHelper->getBundleEntityTypeId($form_entity));
$this->setBundleName($form_entity->id());
$this->setInstanceId(NULL);
break;
if (FALSE === $form_entity = $this->getFormEntity()) {
return FALSE;
}
case 'instance':
$this->setEntityTypeId($entity_type_id);
$this->setBundleName($this->entityHelper->getEntityInstanceBundleName($form_entity));
// New menu link's id is '' instead of NULL, hence checking for empty.
$this->setInstanceId(!empty($form_entity->id()) ? $form_entity->id() : NULL);
$entity_type_id = $form_entity->getEntityTypeId();
$sitemap_entity_types = $this->entityHelper->getSupportedEntityTypes();
if (isset($sitemap_entity_types[$entity_type_id])) {
$this->setEntityCategory('instance');
}
else {
/**
* @var \Drupal\Core\Entity\EntityType $sitemap_entity_type
*/
foreach ($sitemap_entity_types as $sitemap_entity_type) {
if ($sitemap_entity_type->getBundleEntityType() === $entity_type_id) {
$this->setEntityCategory('bundle');
break;
default:
return FALSE;
}
}
return TRUE;
}
return FALSE;
// Menu fix.
$this->setEntityCategory(NULL === $this->getEntityCategory() && $entity_type_id == 'menu' ? 'bundle' : $this->getEntityCategory());
switch ($this->getEntityCategory()) {
case 'bundle':
$this->setEntityTypeId($this->entityHelper->getBundleEntityTypeId($form_entity));
$this->setBundleName($form_entity->id());
$this->setInstanceId(NULL);
break;
case 'instance':
$this->setEntityTypeId($entity_type_id);
$this->setBundleName($this->entityHelper->getEntityInstanceBundleName($form_entity));
// New menu link's id is '' instead of NULL, hence checking for empty.
$this->setInstanceId(!empty($form_entity->id()) ? $form_entity->id() : NULL);
break;
default:
return FALSE;
}
return TRUE;
}
/**
......
......@@ -33,7 +33,7 @@ class SimplesitemapCustomLinksForm extends SimplesitemapFormBase {
'#type' => 'textarea',
'#title' => $this->t('Relative Drupal paths'),
'#default_value' => $this->customLinksToString($this->generator->getCustomLinks(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']['include_images'] = [
......@@ -67,22 +67,22 @@ class SimplesitemapCustomLinksForm extends SimplesitemapFormBase {
// if (!$this->pathValidator->getUrlIfValidWithoutAccessCheck($link_config['path']) //todo
// Path validator does not see a double slash as an error. Catching this to prevent breaking path generation.
|| strpos($link_config['path'], '//') !== FALSE) {
$form_state->setErrorByName('', $this->t("<strong>Line @line</strong>: The path <em>@path</em> does not exist.", $placeholders));
$form_state->setErrorByName('', $this->t('<strong>Line @line</strong>: The path <em>@path</em> does not exist.', $placeholders));
}
// Making sure the paths start with a slash.
if ($link_config['path'][0] != '/') {
$form_state->setErrorByName('', $this->t("<strong>Line @line</strong>: The path <em>@path</em> needs to start with a '/'.", $placeholders));
$form_state->setErrorByName('', $this->t('<strong>Line @line</strong>: The path <em>@path</em> needs to start with a \'/\'.', $placeholders));
}
// Making sure the priority is formatted correctly.
if (isset($link_config['priority']) && !FormHelper::isValidPriority($link_config['priority'])) {
$form_state->setErrorByName('', $this->t("<strong>Line @line</strong>: The priority setting <em>@priority</em> for path <em>@path</em> is incorrect. Set the priority from 0.0 to 1.0.", $placeholders));
$form_state->setErrorByName('', $this->t('<strong>Line @line</strong>: The priority setting <em>@priority</em> for path <em>@path</em> is incorrect. Set the priority from 0.0 to 1.0.', $placeholders));
}
// Making sure changefreq is formatted correctly.
if (isset($link_config['changefreq']) && !FormHelper::isValidChangefreq($link_config['changefreq'])) {
$form_state->setErrorByName('', $this->t("<strong>Line @line</strong>: The changefreq setting <em>@changefreq</em> for path <em>@path</em> is incorrect. The following are the correct values: <em>@changefreq_options</em>.", $placeholders));
$form_state->setErrorByName('', $this->t('<strong>Line @line</strong>: The changefreq setting <em>@changefreq</em> for path <em>@path</em> is incorrect. The following are the correct values: <em>@changefreq_options</em>.', $placeholders));
}
}
}
......
......@@ -27,7 +27,7 @@ class SimplesitemapEntitiesForm extends SimplesitemapFormBase {
$form['simple_sitemap_entities']['entities'] = [
'#title' => $this->t('Sitemap entities'),
'#type' => 'fieldset',
'#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>',
'#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';
......@@ -60,9 +60,9 @@ class SimplesitemapEntitiesForm extends SimplesitemapFormBase {
if ($form['simple_sitemap_entities']['entities'][$entity_type_id][$entity_type_id . '_enabled']['#default_value']) {
$form['simple_sitemap_entities']['entities'][$entity_type_id][$entity_type_id . '_enabled']['#suffix']
= "<div id='warning-$css_entity_type_id'>"
. $this->t("<strong>Warning:</strong> This entity type's sitemap settings including per-entity overrides will be deleted after hitting <em>Save</em>.")
. "</div>";
= '<div id="warning-' . $css_entity_type_id . '">'
. $this->t('<strong>Warning:</strong> This entity type\'s sitemap settings including per-entity overrides will be deleted after hitting <em>Save</em>.')
. '</div>';
}
$form['#attached']['drupalSettings']['simple_sitemap']['all_entities'][] = $css_entity_type_id;
......
......@@ -86,7 +86,7 @@ abstract class SimplesitemapFormBase extends ConfigFormBase {
*
*/
protected function getDonationText() {
return "<div class='description'>" . $this->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>";
return '<div class="description">' . $this->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>';
}
}
......@@ -102,7 +102,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, however it is advisable to set this to a lower number. 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, however it is advisable to set this to a lower number. If left blank, all links will be shown on a single sitemap.'),
'#default_value' => $this->generator->getSetting('max_links', 2000),
];
......@@ -110,7 +110,7 @@ class SimplesitemapSettingsForm extends SimplesitemapFormBase {
'#type' => 'number',
'#title' => $this->t('Refresh batch every n links'),
'#min' => 1,
'#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.<br/>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."),
'#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.<br/>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.'),
'#default_value' => $this->generator->getSetting('batch_process_limit', 1500),
'#required' => TRUE,
];
......
......@@ -25,7 +25,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
*/
class CustomUrlGenerator extends UrlGeneratorBase {
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>.";
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>.';
/**
......@@ -61,8 +61,7 @@ class CustomUrlGenerator extends UrlGeneratorBase {
EntityTypeManagerInterface $entity_type_manager,
Logger $logger,
EntityHelper $entityHelper,
PathValidator $path_validator
) {
PathValidator $path_validator) {
parent::__construct(
$configuration,
$plugin_id,
......
......@@ -346,7 +346,7 @@ abstract class UrlGeneratorBase extends SimplesitemapPluginBase implements UrlGe
// Update chunk count info.
$this->setChunkCount(empty($this->getChunkCount()) ? 1 : ($this->getChunkCount() + 1));
// Update remove links from array that have been generated.
// Remove links from result array that have been generated.
$this->setBatchResults(array_slice($this->getBatchResults(), count($chunk_links)));
}
}
......
......@@ -89,12 +89,6 @@ class Simplesitemap {
'include_images' => 0,
];
protected static $generatorServices = [
'simple_sitemap.custom_url_generator',
'simple_sitemap.entity_url_generator',
'simple_sitemap.arbitrary_url_generator',
];
/**
* Simplesitemap constructor.
* @param \Drupal\simple_sitemap\SitemapGenerator $sitemapGenerator
......@@ -163,7 +157,7 @@ class Simplesitemap {
* @return $this
*/
public function saveSetting($name, $setting) {
$this->configFactory->getEditable("simple_sitemap.settings")
$this->configFactory->getEditable('simple_sitemap.settings')
->set($name, $setting)->save();
return $this;
}
......@@ -212,7 +206,7 @@ class Simplesitemap {
*/
protected function fetchSitemapChunkInfo() {
return $this->db
->query("SELECT id, sitemap_created FROM {simple_sitemap}")
->query('SELECT id, sitemap_created FROM {simple_sitemap}')
->fetchAllAssoc('id');
}
......@@ -312,7 +306,7 @@ class Simplesitemap {
* setBundleSettings() as well.
*
* @param string $entity_type_id
* Entity type id like 'node'.
* Entity type id like 'node'.
*
* @return $this
*/
......@@ -360,12 +354,12 @@ class Simplesitemap {
* of an entity type (e.g. page).
*
* @param string $entity_type_id
* Entity type id like 'node' the bundle belongs to.
* Entity type id like 'node' the bundle belongs to.
* @param string $bundle_name
* Name of the bundle. NULL if entity type has no bundles.
* Name of the bundle. NULL if entity type has no bundles.
* @param array $settings
* An array of sitemap settings for this bundle/entity type.
* Example: ['index' => TRUE, 'priority' => 0.5, 'changefreq' => 'never', 'include_images' => FALSE].
* An array of sitemap settings for this bundle/entity type.
* Example: ['index' => TRUE, 'priority' => 0.5, 'changefreq' => 'never', 'include_images' => FALSE].
*
* @return $this
*
......@@ -374,8 +368,12 @@ class Simplesitemap {
public function setBundleSettings($entity_type_id, $bundle_name = NULL, $settings = []) {
$bundle_name = empty($bundle_name) ? $entity_type_id : $bundle_name;
$old_settings = $this->getBundleSettings($entity_type_id, $bundle_name);
$settings = !empty($old_settings) ? array_merge($old_settings, $settings) : $this->supplementDefaultSettings('entity', $settings);
if (!empty($old_settings = $this->getBundleSettings($entity_type_id, $bundle_name))) {
$settings = array_merge($old_settings, $settings);
}
else {
self::supplementDefaultSettings('entity', $settings);
}
$bundle_settings = $this->configFactory
->getEditable("simple_sitemap.bundle_settings.$entity_type_id.$bundle_name");
......@@ -458,7 +456,7 @@ class Simplesitemap {
return !empty($bundle_settings) ? $bundle_settings : FALSE;
}
else {
$config_names = $this->configFactory->listAll("simple_sitemap.bundle_settings.");
$config_names = $this->configFactory->listAll('simple_sitemap.bundle_settings.');
$all_settings = [];
foreach($config_names as $config_name) {
$config_name_parts = explode('.', $config_name);
......@@ -472,17 +470,18 @@ class Simplesitemap {
* Supplements all missing link setting with default values.
*
* @param string $type
* @param array $settings
* @return array
* 'entity'|'custom'
* @param array &$settings
* @param array $overrides
*/
protected function supplementDefaultSettings($type, $settings) {
public static function supplementDefaultSettings($type, &$settings, $overrides = []) {
foreach(self::$allowedLinkSettings[$type] as $allowed_link_setting) {
if (!isset($settings[$allowed_link_setting])
&& isset(self::$linkSettingDefaults[$allowed_link_setting])) {
$settings[$allowed_link_setting] = self::$linkSettingDefaults[$allowed_link_setting];
}
}
return $settings;
$settings = array_merge($settings, $overrides);
}
/**
......@@ -636,7 +635,7 @@ class Simplesitemap {
}
$link_key = isset($link_key) ? $link_key : count($custom_links);
$custom_links[$link_key] = ['path' => $path] + $settings;
$this->configFactory->getEditable("simple_sitemap.custom")
$this->configFactory->getEditable('simple_sitemap.custom')
->set('links', $custom_links)->save();
return $this;
}
......@@ -654,7 +653,8 @@ class Simplesitemap {
if ($supplement_default_settings) {
foreach ($custom_links as $i => $link_settings) {
$custom_links[$i] = $this->supplementDefaultSettings('custom', $link_settings);
self::supplementDefaultSettings('custom', $link_settings);
$custom_links[$i] = $link_settings;
}
}
......@@ -690,7 +690,7 @@ class Simplesitemap {
if ($link['path'] === $path) {
unset($custom_links[$key]);
$custom_links = array_values($custom_links);
$this->configFactory->getEditable("simple_sitemap.custom")
$this->configFactory->getEditable('simple_sitemap.custom')
->set('links', $custom_links)->save();
break;
}
......@@ -704,7 +704,7 @@ class Simplesitemap {
* @return $this
*/
public function removeCustomLinks() {
$this->configFactory->getEditable("simple_sitemap.custom")
$this->configFactory->getEditable('simple_sitemap.custom')
->set('links', [])->save();
return $this;
}
......
......@@ -178,6 +178,7 @@ class SitemapGenerator {
$this->writer->endElement();
$this->writer->endDocument();
return $this->writer->outputMemory();
}
......@@ -263,6 +264,7 @@ class SitemapGenerator {
}
$this->writer->endElement();
$this->writer->endDocument();
return $this->writer->outputMemory();
}
......
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