Commit 3bac331a authored by gbyte.co's avatar gbyte.co

Split simple_sitemap.entity_types into individual configuration objects for each bundle.

parent a4e20977
node: []
taxonomy_term: []
menu_link_content: []
......@@ -3,3 +3,7 @@ cron_generate: true
remove_duplicates: true
skip_untranslated: false
batch_process_limit: 1500
enabled_entity_types:
- 'node'
- 'taxonomy_term'
- 'menu_link_content'
......@@ -16,24 +16,25 @@ simple_sitemap.settings:
batch_process_limit:
label: 'Batch process limit'
type: integer
enabled_entity_types:
label: 'Enabled entity types'
type: sequence
sequence:
type: string
simple_sitemap.entity_types:
simple_sitemap.bundle_settings.*.*:
label: 'Entity bundle settings'
type: config_object
mapping:
type: sequence
sequence:
type: sequence
sequence:
type: mapping
mapping:
index:
label: 'Index'
type: integer
priority:
label: 'Priority'
type: string
index:
label: 'Index'
type: integer
priority:
label: 'Priority'
type: string
simple_sitemap.custom:
label: 'Custom links'
type: config_object
sequence:
type: mapping
......
......@@ -11,13 +11,10 @@
$(context).find('#edit-simple-sitemap').drupalSetSummary(function(context) {
var vals = [];
if ($(context).find('#edit-simple-sitemap-index-content-1').is(':checked')) {
// Display summary of the settings in tabs.
vals.push(Drupal.t('Included in sitemap'));
vals.push(Drupal.t('Priority') + ' ' + $('#edit-simple-sitemap-priority option:selected', context).text());
}
else {
// Display summary of the settings in tabs.
vals.push(Drupal.t('Excluded from sitemap'));
}
return vals.join('<br />');
......
......@@ -221,7 +221,7 @@ function simple_sitemap_update_8203() {
}
/**
* Remove entity type settings for entity types which do not have the canonical
* Removing entity type settings for entity types which do not have the canonical
* link template.
*/
function simple_sitemap_update_8204() {
......@@ -244,3 +244,32 @@ function simple_sitemap_update_8204() {
\Drupal::service('config.factory')->getEditable("simple_sitemap.entity_types")
->setData($entity_types)->save();
}
/**
* Splitting simple_sitemap.entity_types into individual configuration objects
* for each bundle.
*/
function simple_sitemap_update_8205() {
$entity_types = \Drupal::config('simple_sitemap.entity_types')->get();
unset($entity_types['_core']);
$enabled_entity_types = [];
foreach($entity_types as $entity_type_id => $bundles) {
$enabled_entity_types[] = $entity_type_id;
foreach($bundles as $bundle_name => $bundle_settings) {
\Drupal::service('config.factory')
->getEditable("simple_sitemap.bundle_settings.$entity_type_id.$bundle_name")
->setData($bundle_settings)->save();
}
}
// Add enabled entity type settings.
\Drupal::service('config.factory')
->getEditable('simple_sitemap.settings')
->set('enabled_entity_types', $enabled_entity_types)
->save();
// Remove old configuration object.
\Drupal::service('config.factory')
->getEditable('simple_sitemap.entity_types')
->delete();
}
......@@ -7,6 +7,7 @@
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\system\MenuInterface;
/**
* Implements hook_help.
......@@ -34,15 +35,18 @@ function simple_sitemap_form_alter(&$form, $form_state, $form_id) {
'#title' => t('Simple XML sitemap'),
'#description' => $f->entityCategory == '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->entityTypeId != 'comment' || $f->entityCategory != 'instance') {
$form['#attached']['library'][] = 'simple_sitemap/form';
}
// Only attach fieldset summary js to 'additional settings' vertical tabs.
if (isset($form['additional_settings'])) {
$form['#attached']['library'][] = 'simple_sitemap/fieldsetSummaries';
}
$f->displayEntitySettings($form['simple_sitemap'])
// todo: do not show setting when creating new bundle.
->displayRegenerateNow($form['simple_sitemap']);
......@@ -107,36 +111,14 @@ function simple_sitemap_cron() {
}
}
/**
* Implements hook_entity_bundle_delete().
*
* Removes settings of the removed bundle.
*
* @todo Not working for menu bundles, as they are technically not bundles. Implement hook_menu_delete().
* @todo delete entity overrides
*/
function simple_sitemap_entity_bundle_delete($entity_type_id, $bundle) {
$generator = \Drupal::service('simple_sitemap.generator');
$entity_types = $generator->getConfig('entity_types');
if (isset($entity_types[$entity_type_id][$bundle])) {
unset($entity_types[$entity_type_id][$bundle]);
$generator->saveConfig('entity_types', $entity_types);
$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 on the next cron run.';
}
drupal_set_message(t($message, ['@url' => $GLOBALS['base_url'] . '/admin/config/search/simplesitemap']));
}
}
/**
* Implements hook_entity_delete().
*
* Removes settings of the removed entity.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
*/
function simple_sitemap_entity_delete(EntityInterface $entity) {
\Drupal::database()->delete('simple_sitemap_entity_overrides')
->condition('entity_type', $entity->getEntityTypeId())
->condition('entity_id', $entity->id())
->execute();
\Drupal::service('simple_sitemap.generator')
->removeEntityInstanceSettings($entity->getEntityTypeId(), $entity->id());
}
......@@ -6,6 +6,7 @@ services:
- '@simple_sitemap.sitemap_generator'
- '@config.factory'
- '@database'
- '@entity.query'
- '@entity_type.manager'
- '@path.validator'
- '@date.formatter'
......
......@@ -415,5 +415,4 @@ class BatchUrlGenerator {
->log('error');
}
}
}
......@@ -322,7 +322,6 @@ class FormHelper {
* @return bool
*/
public static function isValidPriority($priority) {
return !is_numeric($priority) || $priority < 0 || $priority > 1 ? FALSE : TRUE;
return is_numeric($priority) && $priority >= 0 && $priority <= 1;
}
}
......@@ -24,7 +24,7 @@ class SimplesitemapCustomLinksForm extends SimplesitemapFormBase {
public function buildForm(array $form, FormStateInterface $form_state) {
$setting_string = '';
foreach ($this->generator->getConfig('custom') as $custom_link) {
foreach ($this->generator->getCustomLinks() as $custom_link) {
$setting_string .= isset($custom_link['priority'])
? $custom_link['path'] . ' ' . $this->formHelper->formatPriority($custom_link['priority'])
: $custom_link['path'];
......
......@@ -43,12 +43,15 @@ class SimplesitemapEntitiesForm extends SimplesitemapFormBase {
$this->formHelper->processForm($form_state);
foreach ($entity_type_labels as $entity_type_id => $entity_type_label) {
$css_entity_type_id = str_replace('_', '-', $entity_type_id);
$form['simple_sitemap_entities']['entities'][$entity_type_id] = [
'#type' => 'details',
'#title' => $entity_type_label,
'#open' => $this->generator->entityTypeIsEnabled($entity_type_id),
];
$form['simple_sitemap_entities']['entities'][$entity_type_id][$entity_type_id . '_enabled'] = [
'#type' => 'checkbox',
'#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]),
......@@ -64,6 +67,7 @@ class SimplesitemapEntitiesForm extends SimplesitemapFormBase {
}
$form['#attached']['drupalSettings']['simple_sitemap']['all_entities'][] = $css_entity_type_id;
if ($this->generator->entityTypeIsAtomic($entity_type_id)) {
$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.');
$this->formHelper->setEntityCategory('bundle')
......@@ -73,7 +77,9 @@ class SimplesitemapEntitiesForm extends SimplesitemapFormBase {
$form['#attached']['drupalSettings']['simple_sitemap']['atomic_entities'][] = $css_entity_type_id;
}
}
$this->formHelper->displayRegenerateNow($form['simple_sitemap_entities']['entities']);
return parent::buildForm($form, $form_state);
}
......
This diff is collapsed.
......@@ -78,7 +78,7 @@ class SitemapGenerator {
'max_links' => $this->generator->getSetting('max_links', 2000),
'skip_untranslated' => $this->generator->getSetting('skip_untranslated', FALSE),
'remove_duplicates' => $this->generator->getSetting('remove_duplicates', TRUE),
'entity_types' => $this->generator->getConfig('entity_types'),
'entity_types' => $this->generator->getBundleSettings(),
]);
// Add custom link generating operation.
$this->batch->addOperation('generateCustomUrls', $this->getCustomUrlsData());
......@@ -98,7 +98,7 @@ class SitemapGenerator {
*/
private function getCustomUrlsData() {
$paths = [];
foreach ($this->generator->getConfig('custom') as $i => $custom_path) {
foreach ($this->generator->getCustomLinks() as $i => $custom_path) {
$paths[$i]['path'] = $custom_path['path'];
$paths[$i]['priority'] = isset($custom_path['priority']) ? $custom_path['priority'] : NULL;
// todo: implement lastmod.
......@@ -116,7 +116,7 @@ class SitemapGenerator {
private function getEntityTypeData() {
$data_sets = [];
$sitemap_entity_types = $this->generator->getSitemapEntityTypes();
$entity_types = $this->generator->getConfig('entity_types');
$entity_types = $this->generator->getBundleSettings();
foreach ($entity_types as $entity_type_name => $bundles) {
if (isset($sitemap_entity_types[$entity_type_name])) {
$keys = $sitemap_entity_types[$entity_type_name]->getKeys();
......
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