Commit b7aeda24 authored by gbyte.co's avatar gbyte.co Committed by gbyte.co

Issue #2961236 by gbyte.co: Allow assigning any bundle to any sitemap variant via UI

parent 8658b74e
...@@ -39,7 +39,7 @@ simple_sitemap.settings: ...@@ -39,7 +39,7 @@ simple_sitemap.settings:
sequence: sequence:
type: string type: string
simple_sitemap.bundle_settings.*.*: simple_sitemap.bundle_settings.*.*.*:
label: 'Entity bundle settings' label: 'Entity bundle settings'
type: config_object type: config_object
mapping: mapping:
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
var vals = []; var vals = [];
if ($(context).find('#edit-simple-sitemap-index-content-1').is(':checked')) { if ($(context).find('#edit-simple-sitemap-index-content-1').is(':checked')) {
vals.push(Drupal.t('Included in sitemap')); vals.push(Drupal.t('Included in sitemap'));
vals.push(Drupal.t('Variant') + ': ' + $('#edit-simple-sitemap-variant option:selected', context).text());
vals.push(Drupal.t('Priority') + ': ' + $('#edit-simple-sitemap-priority option:selected', context).text()); vals.push(Drupal.t('Priority') + ': ' + $('#edit-simple-sitemap-priority option:selected', context).text());
vals.push(Drupal.t('Change frequency') + ': ' + $('#edit-simple-sitemap-changefreq option:selected', context).text()); vals.push(Drupal.t('Change frequency') + ': ' + $('#edit-simple-sitemap-changefreq option:selected', context).text());
vals.push(Drupal.t('Include images') + ': ' + $('#edit-simple-sitemap-include-images option:selected', context).text()); vals.push(Drupal.t('Include images') + ': ' + $('#edit-simple-sitemap-include-images option:selected', context).text());
......
...@@ -12,36 +12,13 @@ ...@@ -12,36 +12,13 @@
// On load: Hide the 'Regenerate sitemap' field to only display it if settings have changed. // On load: Hide the 'Regenerate sitemap' field to only display it if settings have changed.
$('.form-item-simple-sitemap-regenerate-now').hide(); $('.form-item-simple-sitemap-regenerate-now').hide();
// On load: Show or hide settings dependant on 'enabled' setting.
if ($('#edit-simple-sitemap-index-content-1').is(':checked')) {
$('.form-item-simple-sitemap-priority').show();
$('.form-item-simple-sitemap-changefreq').show();
$('.form-item-simple-sitemap-include-images').show();
}
else {
$('.form-item-simple-sitemap-priority').hide();
$('.form-item-simple-sitemap-changefreq').hide();
$('.form-item-simple-sitemap-include-images').hide();
}
// On change: Show or hide settings dependant on 'enabled' setting.
$("#edit-simple-sitemap-index-content").change(function() {
if ($('#edit-simple-sitemap-index-content-1').is(':checked')) {
$('.form-item-simple-sitemap-priority').show();
$('.form-item-simple-sitemap-changefreq').show();
$('.form-item-simple-sitemap-include-images').show();
}
else {
$('.form-item-simple-sitemap-priority').hide();
$('.form-item-simple-sitemap-changefreq').hide();
$('.form-item-simple-sitemap-include-images').hide();
}
// Show 'Regenerate sitemap' field if 'enabled' setting has changed.
$('.form-item-simple-sitemap-regenerate-now').show();
});
// Show 'Regenerate sitemap' field if settings have changed. // Show 'Regenerate sitemap' field if settings have changed.
$("#edit-simple-sitemap-priority, #edit-simple-sitemap-changefreq, #edit-simple-sitemap-include-images").change(function() { $("#edit-simple-sitemap-index-content"
+ ", #edit-simple-sitemap-variant"
+ ", #edit-simple-sitemap-priority"
+ ", #edit-simple-sitemap-changefreq"
+ ", #edit-simple-sitemap-include-images"
).change(function() {
$('.form-item-simple-sitemap-regenerate-now').show(); $('.form-item-simple-sitemap-regenerate-now').show();
}); });
} }
......
...@@ -36,44 +36,18 @@ ...@@ -36,44 +36,18 @@
}); });
}); });
// Show settings if atomic entity enabled on form load. // todo
$.each(atomicEntities, function(index, value) { // Show 'Regenerate sitemap' field if settings have changed.
var enabledId = '#edit-' + value + '-enabled'; // $.each(atomicEntities, function(index, value) {
var priorityId = '.form-item-' + value + '-simple-sitemap-priority'; // var variant = '.form-item-' + value + '-simple-sitemap-variant';
var changefreqId = '.form-item-' + value + '-simple-sitemap-changefreq'; // var priorityId = '.form-item-' + value + '-simple-sitemap-priority';
var includeImagesId = '.form-item-' + value + '-simple-sitemap-include-images'; // var changefreqId = '.form-item-' + value + '-simple-sitemap-changefreq';
// var includeImagesId = '.form-item-' + value + '-simple-sitemap-include-images';
// On load: Show or hide settings dependent on 'enabled' checkbox. //
if ($(enabledId).is(':checked')) { // $(variant, priorityId, changefreqId, includeImagesId).change(function() {
$(priorityId).show(); // $('.form-item-simple-sitemap-regenerate-now').show();
$(changefreqId).show(); // });
$(includeImagesId).show(); // });
}
else {
$(priorityId).hide();
$(changefreqId).hide();
$(includeImagesId).hide();
}
// On change: Show or hide settings dependent on 'enabled' checkbox.
$(enabledId).change(function() {
if ($(enabledId).is(':checked')) {
$(priorityId).show();
$(changefreqId).show();
$(includeImagesId).show();
}
else {
$(priorityId).hide();
$(changefreqId).hide();
$(includeImagesId).hide();
}
});
// Show 'Regenerate sitemap' field if settings have changed.
$(priorityId, changefreqId, includeImagesId).change(function() {
$('.form-item-simple-sitemap-regenerate-now').show();
});
});
} }
}; };
})(jQuery); })(jQuery);
...@@ -27,39 +27,41 @@ function simple_sitemap_requirements($phase) { ...@@ -27,39 +27,41 @@ function simple_sitemap_requirements($phase) {
case 'runtime': case 'runtime':
$generator = \Drupal::service('simple_sitemap.generator'); // todo Implement for 3.x
$generated_ago = $generator->getGeneratedAgo(\Drupal\simple_sitemap\SimplesitemapManager::DEFAULT_SITEMAP_VARIANT); //todo // /** @var \Drupal\simple_sitemap\Simplesitemap $generator */
$cron_generation = $generator->getSetting('cron_generate'); // $generator = \Drupal::service('simple_sitemap.generator');
// $generated_ago = $generator->getGeneratedAgo();
if (!$generated_ago) { // $cron_generation = $generator->getSetting('cron_generate');
$value = t('Not available'); //
$description = t($cron_generation // if (!$generated_ago) {
? 'Run cron, or <a href="@generate">generate</a> the sitemap manually.' // $value = t('Not available');
: 'Generation on cron run is disabled. <a href="@generate">Generate</a> the sitemap manually.', [ // $description = t($cron_generation
'@generate' => $GLOBALS['base_url'] . '/admin/config/search/simplesitemap' // ? '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'
$severity = REQUIREMENT_WARNING; // ]
} // );
else { // $severity = REQUIREMENT_WARNING;
$value = t('XML sitemaps are available'); // }
$description = t('The last generation finished @ago ago.' // else {
. ' ' . ($cron_generation // $value = t('XML sitemaps are available');
? 'Run cron, or <a href="@generate">regenerate</a> the sitemaps manually.' // $description = t('The last generation finished @ago ago.'
: 'Generation on cron run is disabled. <a href="@generate">Regenerate</a> the sitemaps manually.'), [ // . ' ' . ($cron_generation
'@ago' => $generated_ago, // ? 'Run cron, or <a href="@generate">regenerate</a> the sitemaps manually.'
'@generate' => $GLOBALS['base_url'] . '/admin/config/search/simplesitemap' // : 'Generation on cron run is disabled. <a href="@generate">Regenerate</a> the sitemaps manually.'), [
] // '@ago' => $generated_ago,
); // '@generate' => $GLOBALS['base_url'] . '/admin/config/search/simplesitemap'
$severity = REQUIREMENT_INFO; // ]
} // );
// $severity = REQUIREMENT_INFO;
$requirements['simple_sitemap_generated'] = [ // }
'title' => 'Simple XML sitemap', //
'value' => $value, // $requirements['simple_sitemap_generated'] = [
'description' => $description, // 'title' => 'Simple XML sitemap',
'severity' => $severity, // 'value' => $value,
]; // 'description' => $description,
// 'severity' => $severity,
// ];
break; break;
} }
return $requirements; return $requirements;
...@@ -142,6 +144,12 @@ function simple_sitemap_schema() { ...@@ -142,6 +144,12 @@ function simple_sitemap_schema() {
'not null' => TRUE, 'not null' => TRUE,
'unsigned' => TRUE, 'unsigned' => TRUE,
], ],
'type' => [
'description' => 'Type of sitemap this override belongs to.',
'type' => 'varchar',
'length' => 50,
'not null' => TRUE,
],
'entity_type' => [ 'entity_type' => [
'description' => 'Entity type of the overriding entity.', 'description' => 'Entity type of the overriding entity.',
'type' => 'varchar', 'type' => 'varchar',
...@@ -459,8 +467,6 @@ function simple_sitemap_update_8210() { ...@@ -459,8 +467,6 @@ function simple_sitemap_update_8210() {
] ]
); );
} }
return t('The XML sitemap needs to be regenerated.');
} }
/** /**
...@@ -607,7 +613,52 @@ function simple_sitemap_update_8215() { ...@@ -607,7 +613,52 @@ function simple_sitemap_update_8215() {
} }
$type->set('variants', $variants)->save(); $type->set('variants', $variants)->save();
} }
}
/**
* Adding per-variant bundle and entity override configuration.
*/
function simple_sitemap_update_8216() {
$config_factory = \Drupal::service('config.factory');
$default_variant = $config_factory->get('simple_sitemap.settings')->get('default_variant');
if (empty($default_variant)) {
$default_variant = 'default';
$config_factory->getEditable('simple_sitemap.settings')
->set('default_variant', $default_variant)
->save();
}
/** @var \Drupal\simple_sitemap\SimplesitemapManager $manager */
$manager = \Drupal::service('simple_sitemap.manager');
$variants = $manager->getSitemapVariants();
if (!isset($variants[$default_variant])) {
$manager->addSitemapVariant($default_variant);
}
foreach ($config_factory->listAll('simple_sitemap.bundle_settings.') as $bundle_config_name) {
/** @var \Drupal\Core\Config\Config $config */
$config = $config_factory->getEditable($bundle_config_name);
$config_name_parts = explode('.', $bundle_config_name);
$config_factory->getEditable($config_name_parts[0] . '.' . $config_name_parts[1]
. '.' . $default_variant . '.' . $config_name_parts[2] . '.' . $config_name_parts[3])
->setData($config->get())->save();
$config->delete();
}
$database = \Drupal::database();
if (!$database->schema()->fieldExists('simple_sitemap_entity_overrides', 'type')) {
$database->schema()->addField(
'simple_sitemap_entity_overrides',
'type', [
'description' => 'Type of sitemap this override belongs to.',
'type' => 'varchar',
'length' => 50,
'not null' => TRUE,
'initial' => 'default',
]
);
}
return t('The XML sitemaps need to be regenerated.'); return t('The XML sitemaps need to be regenerated.');
} }
...@@ -49,8 +49,7 @@ function simple_sitemap_form_alter(&$form, FormStateInterface $form_state, $form ...@@ -49,8 +49,7 @@ function simple_sitemap_form_alter(&$form, FormStateInterface $form_state, $form
]; ];
// Attach some js magic to forms. // Attach some js magic to forms.
// todo: JS not working on comment entity form, hence disabling. if ($f->getEntityCategory() !== 'instance') {
if ($f->getEntityTypeId() !== 'comment' || $f->getEntityCategory() !== 'instance') {
$form['#attached']['library'][] = 'simple_sitemap/form'; $form['#attached']['library'][] = 'simple_sitemap/form';
} }
...@@ -111,21 +110,31 @@ function simple_sitemap_entity_form_submit($form, FormStateInterface &$form_stat ...@@ -111,21 +110,31 @@ function simple_sitemap_entity_form_submit($form, FormStateInterface &$form_stat
'include_images' => (bool) $values['simple_sitemap_include_images'], 'include_images' => (bool) $values['simple_sitemap_include_images'],
]; ];
// Deleting bundle settings for old bundle.
// See SimplesitemapEntitiesForm::submitForm().
// todo: This will not be necessary if "multiple variants pro bundle" 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']) {
$generator->setVariants($old_variant)->removeBundleSettings($f->getEntityTypeId(), $f->getBundleName());
}
}
switch ($f->getEntityCategory()) { switch ($f->getEntityCategory()) {
case 'bundle': case 'bundle':
$generator->setBundleSettings( $generator->setVariants([$values['simple_sitemap_variant']])
$f->getEntityTypeId(), ->setBundleSettings($f->getEntityTypeId(),
!empty($f->getBundleName()) ? $f->getBundleName() : $f->getFormEntityId(), !empty($f->getBundleName()) ? $f->getBundleName() : $f->getFormEntityId(),
$settings $settings
); );
break; break;
case 'instance': case 'instance':
$generator->setEntityInstanceSettings( $generator->setVariants([$values['simple_sitemap_variant']])
$f->getEntityTypeId(), ->setEntityInstanceSettings($f->getEntityTypeId(),
!empty($f->getInstanceId()) ? $f->getInstanceId() : $f->getFormEntityId(), !empty($f->getInstanceId()) ? $f->getInstanceId() : $f->getFormEntityId(),
$settings $settings
); );
break; break;
} }
...@@ -192,7 +201,7 @@ function simple_sitemap_entity_delete(EntityInterface $entity) { ...@@ -192,7 +201,7 @@ function simple_sitemap_entity_delete(EntityInterface $entity) {
/** @var \Drupal\simple_sitemap\Simplesitemap $generator */ /** @var \Drupal\simple_sitemap\Simplesitemap $generator */
$generator = \Drupal::service('simple_sitemap.generator'); $generator = \Drupal::service('simple_sitemap.generator');
$generator->removeEntityInstanceSettings( $generator->setVariants(TRUE)->removeEntityInstanceSettings(
$entity->getEntityTypeId(), $entity->id() $entity->getEntityTypeId(), $entity->id()
); );
} }
...@@ -206,7 +215,10 @@ function simple_sitemap_entity_delete(EntityInterface $entity) { ...@@ -206,7 +215,10 @@ function simple_sitemap_entity_delete(EntityInterface $entity) {
* @param string $bundle * @param string $bundle
*/ */
function simple_sitemap_entity_bundle_delete($entity_type_id, $bundle) { function simple_sitemap_entity_bundle_delete($entity_type_id, $bundle) {
simple_sitemap_delete_bundle_config($entity_type_id, $bundle);
/** @var \Drupal\simple_sitemap\Simplesitemap $generator */
$generator = \Drupal::service('simple_sitemap.generator');
$generator->setVariants(TRUE)->removeBundleSettings($entity_type_id, $bundle);
} }
/** /**
...@@ -217,33 +229,10 @@ function simple_sitemap_entity_bundle_delete($entity_type_id, $bundle) { ...@@ -217,33 +229,10 @@ function simple_sitemap_entity_bundle_delete($entity_type_id, $bundle) {
* @param \Drupal\system\MenuInterface $menu * @param \Drupal\system\MenuInterface $menu
*/ */
function simple_sitemap_menu_delete(MenuInterface $menu) { function simple_sitemap_menu_delete(MenuInterface $menu) {
simple_sitemap_delete_bundle_config('menu_link_content', $menu->id());
}
/**
* Helper function used by simple_sitemap_entity_bundle_delete() and
* simple_sitemap_menu_delete() hooks. This is needed, as menus are technically
* not bundles.
*
* @param string $entity_type_id
* @param string $bundle
*/
function simple_sitemap_delete_bundle_config($entity_type_id, $bundle) {
/** @var \Drupal\simple_sitemap\Simplesitemap $generator */ /** @var \Drupal\simple_sitemap\Simplesitemap $generator */
$generator = \Drupal::service('simple_sitemap.generator'); $generator = \Drupal::service('simple_sitemap.generator');
$generator->setVariants(TRUE)->removeBundleSettings('menu_link_content', $menu->id());
if (!empty($deleted_bundle_settings = $generator->getBundleSettings($entity_type_id, $bundle))) {
\Drupal::service('config.factory')->getEditable("simple_sitemap.bundle_settings.$entity_type_id.$bundle")->delete();
if (!empty($deleted_bundle_settings['index'])) {
$message = 'You may want to <a href="@url">regenerate</a> your XML sitemaps now.';
if ($generator->getSetting('cron_generate')) {
$message .= ' Otherwise the sitemaps will be regenerated during a future cron run.';
}
\Drupal::messenger()->addMessage(t($message, ['@url' => $GLOBALS['base_url'] . '/admin/config/search/simplesitemap']));
}
}
} }
/** /**
......
...@@ -21,6 +21,7 @@ services: ...@@ -21,6 +21,7 @@ services:
public: false public: false
arguments: arguments:
- '@config.factory' - '@config.factory'
- '@database'
- '@plugin.manager.simple_sitemap.sitemap_type' - '@plugin.manager.simple_sitemap.sitemap_type'
- '@plugin.manager.simple_sitemap.url_generator' - '@plugin.manager.simple_sitemap.url_generator'
- '@plugin.manager.simple_sitemap.sitemap_generator' - '@plugin.manager.simple_sitemap.sitemap_generator'
......
...@@ -59,6 +59,16 @@ class FormHelper { ...@@ -59,6 +59,16 @@ class FormHelper {
*/ */
protected $instanceId; protected $instanceId;
/**
* @var string
*/
protected $variant;
/**
* @var array
*/
protected $bundleSettings;
protected static $allowedFormOperations = [ protected static $allowedFormOperations = [
'default', 'default',
'edit', 'edit',
...@@ -77,6 +87,7 @@ class FormHelper { ...@@ -77,6 +87,7 @@ class FormHelper {
]; ];
protected static $valuesToCheck = [ protected static $valuesToCheck = [
'simple_sitemap_variant',
'simple_sitemap_index_content', 'simple_sitemap_index_content',
'simple_sitemap_priority', 'simple_sitemap_priority',
'simple_sitemap_changefreq', 'simple_sitemap_changefreq',
...@@ -108,6 +119,7 @@ class FormHelper { ...@@ -108,6 +119,7 @@ class FormHelper {
$this->formState = $form_state; $this->formState = $form_state;
$this->cleanUpFormInfo(); $this->cleanUpFormInfo();
$this->getEntityDataFromFormEntity(); $this->getEntityDataFromFormEntity();
$this->negotiateVariant();
return $this->supports(); return $this->supports();
} }
...@@ -197,9 +209,12 @@ class FormHelper { ...@@ -197,9 +209,12 @@ class FormHelper {
// Do not alter the form, if sitemap is disabled for the entity type of this // Do not alter the form, if sitemap is disabled for the entity type of this
// entity instance. // entity instance.
elseif ($this->getEntityCategory() === 'instance' elseif ($this->getEntityCategory() === 'instance') {
&& !$this->generator->bundleIsIndexed($this->getEntityTypeId(), $this->getBundleName())) { if (NULL === $this->variant || !$this->generator
return FALSE; ->setVariants($this->variant)
->bundleIsIndexed($this->getEntityTypeId(), $this->getBundleName())) {
return FALSE;
}
} }
return TRUE; return TRUE;
...@@ -220,6 +235,15 @@ class FormHelper { ...@@ -220,6 +235,15 @@ class FormHelper {
} }
} }
protected 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;
}
/** /**
* @param array $form_fragment * @param array $form_fragment
* @param bool $multiple * @param bool $multiple
...@@ -228,15 +252,9 @@ class FormHelper { ...@@ -228,15 +252,9 @@ class FormHelper {
public function displayEntitySettings(&$form_fragment, $multiple = FALSE) { public function displayEntitySettings(&$form_fragment, $multiple = FALSE) {
$prefix = $multiple ? $this->getEntityTypeId() . '_' : ''; $prefix = $multiple ? $this->getEntityTypeId() . '_' : '';
if ($this->getEntityCategory() === 'instance') { $settings = $this->getEntityCategory() === 'instance' && NULL !== $this->variant && NULL !== $this->getInstanceId()
$bundle_settings = $this->generator->getBundleSettings($this->getEntityTypeId(), $this->getBundleName()); ? $this->generator->setVariants($this->variant)->getEntityInstanceSettings($this->getEntityTypeId(), $this->getInstanceId())
$settings = NULL !== $this->getInstanceId() : $this->bundleSettings;
? $this->generator->getEntityInstanceSettings($this->getEntityTypeId(), $this->getInstanceId())
: $bundle_settings;
}
else {
$settings = $this->generator->getBundleSettings($this->getEntityTypeId(), $this->getBundleName());
}
Simplesitemap::supplementDefaultSettings('entity', $settings); Simplesitemap::supplementDefaultSettings('entity', $settings);
$bundle_name = !empty($this->getBundleName()) ? $this->getBundleName() : $this->t('undefined'); $bundle_name = !empty($this->getBundleName()) ? $this->getBundleName() : $this->t('undefined');
...@@ -256,11 +274,32 @@ class FormHelper { ...@@ -256,11 +274,32 @@ class FormHelper {
], ],
]; ];
if ($this->getEntityCategory() === 'instance' && isset($bundle_settings['index'])) { if ($this->getEntityCategory() === 'instance' && isset($this->bundleSettings['index'])) {
$form_fragment[$prefix . 'simple_sitemap_index_content']['#options'][(int) $bundle_settings['index']] .= ' <em>(' . $this->t('default') . ')</em>'; $form_fragment[$prefix . 'simple_sitemap_index_content']['#options'][(int) $this->bundleSettings['index']] .= ' <em>(' . $this->t('default') . ')</em>';
} }
} }
// Variant
$variants = $this->generator->getSitemapManager()->getSitemapVariants(NULL, FALSE);
$variants = array_map(function($variant) { return $variant['label']; }, $variants);
$form_fragment[$prefix . 'simple_sitemap_variant'] = [
'#type' => 'select',
'#title' => $this->t('Sitemap variant'),
'#description' => $this->t('The sitemap variant entities of this type are to be indexed in.'),
'#options' => $variants,
'#default_value' => $this->variant,
'#states' => [
'visible' => !$multiple
? [':input[name="' . $prefix . 'simple_sitemap_index_content"]' => ['value' => 1]]
: [':input[name="' . $prefix . 'enabled"]' => ['checked' => TRUE]],
'required' => !$multiple // todo Should implement server side validation on top of this.
? [':input[name="' . $prefix . 'simple_sitemap_index_content"]' => ['value' => 1]]
: [':input[name="' . $prefix . 'enabled"]' => ['checked' => TRUE]],
],
'#disabled' => $this->getEntityCategory() === 'instance'
];
// Priority // Priority
$form_fragment[$prefix . 'simple_sitemap_priority'] = [ $form_fragment[$prefix . 'simple_sitemap_priority'] = [
'#type' => 'select', '#type' => 'select',
...@@ -270,10 +309,15 @@ class FormHelper { ...@@ -270,10 +309,15 @@ class FormHelper {
: $this->t('The priority entities of this type will have in the eyes of search engine bots.'), : $this->t('The priority entities of this type will have in the eyes of search engine bots.'),
'#default_value' => $settings['priority'], '#default_value' => $settings['priority'],
'#options' => $this->getPrioritySelectValues(), '#options' => $this->getPrioritySelectValues(),
'#states' => [
'visible' => !$multiple
? [':input[name="' . $prefix . 'simple_sitemap_index_content"]' => ['value' => 1]]
: [':input[name="' . $prefix . 'enabled"]' => ['checked' => TRUE]],
],
]; ];
if ($this->getEntityCategory() === 'instance' && isset($bundle_settings['priority'])) { if ($this->getEntityCategory() === 'instance' && isset($this->bundleSettings['priority'])) {
$form_fragment[$prefix . 'simple_sitemap_priority']['#options'][$this->formatPriority($bundle_settings['priority'])] .= ' (' . $this->t('default') . ')'; $form_fragment[$prefix . 'simple_sitemap_priority']['#options'][$this->formatPriority($this->bundleSettings['priority'])] .= ' (' . $this->t('default') . ')';
} }
// Changefreq // Changefreq
...@@ -285,10 +329,15 @@ class FormHelper { ...@@ -285,10 +329,15 @@ class FormHelper {
: $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.'), : $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' => $settings['changefreq'], '#default_value' => $settings['changefreq'],
'#options' => $this->getChangefreqSelectValues(), '#options' => $this->getChangefreqSelectValues(),
'#states' => [
'visible' => !$multiple
? [':input[name="' . $prefix . 'simple_sitemap_index_content"]' => ['value' => 1]]
: [':input[name="' . $prefix . 'enabled"]' => ['checked' => TRUE]],
],
]; ];
if ($this->getEntityCategory() === 'instance' && isset($bundle_settings['changefreq'])) { if ($this->getEntityCategory() === 'instance' && isset($this->bundleSettings['changefreq'])) {
$form_fragment[$prefix . 'simple_sitemap_changefreq']['#options'][$bundle_settings['changefreq']] .= ' (' . $this->t('default') . ')'; $form_fragment[$prefix . 'simple_sitemap_changefreq']['#options'][$this->bundleSettings['changefreq']] .= ' (' . $this->t('default') . ')';
} }
// Images // Images
...@@ -300,10 +349,15 @@ class FormHelper { ...@@ -300,10 +349,15 @@ class FormHelper {
: $this->t('Determines if images referenced by entities of this type should be included in the sitemap.'), : $this->t('Determines if images referenced by entities of this type should be included in the sitemap.'),
'#default_value' => (int) $settings['include_images'], '#default_value' => (int) $settings['include_images'],
'#options' => [0 => $this->t('No'), 1 => $this->t('Yes')], '#options' => [0 => $this->t('No'), 1 => $this->t('Yes')],
'#states' => [
'visible' => !$multiple
? [':input[name="' . $prefix . 'simple_sitemap_index_content"]' => ['value' => 1]]
: [':input[name="' . $prefix . 'enabled"]' => ['checked' => TRUE]],
],
]; ];
if ($this->getEntityCategory() === 'instance' && isset($bundle_settings['include_images'])) { if ($this->getEntityCategory() === 'instance' && isset($this->bundleSettings['include_images'])) {
$form_fragment[$prefix . 'simple_sitemap_include_images']['#options'][(int) $bundle_settings['include_images']] .= ' (' . $this->t('default') . ')'; $form_fragment[$prefix . 'simple_sitemap_include_images']['#options'][(int) $this->bundleSettings['include_images']] .= ' (' . $this->t('default') . ')';
} }
return $this; return $this;
...@@ -327,9 +381,7 @@ class FormHelper { ...@@ -327,9 +381,7 @@ class FormHelper {
$this->setEntityCategory('instance'); $this->setEntityCategory('instance');
} }
else { else {
/** /** @var \Drupal\Core\Entity\EntityType $sitemap_entity_type */
* @var \Drupal\Core\Entity\EntityType $sitemap_entity_type
*/
foreach ($sitemap_entity_types as $sitemap_entity_type) { foreach ($sitemap_entity_types as $sitemap_entity_type) {
if ($sitemap_entity_type->getBundleEntityType() === $entity_type_id) { if ($sitemap_entity_type->getBundleEntityType() === $entity_type_id) {
$this->setEntityCategory('bundle'); $this->setEntityCategory('bundle');
...@@ -390,6 +442,8 @@ class FormHelper { ...@@ -390,6 +442,8 @@ class FormHelper {
$this->entityTypeId = NULL; $this->entityTypeId = NULL;
$this->bundleName = NULL; $this->bundleName = NULL;
$this->instanceId = NULL; $this->instanceId = NULL;
$this->variant = NULL;
$this->bundleSettings = NULL;
} }
/** /**
...@@ -415,7 +469,8 @@ class FormHelper { ...@@ -415,7 +469,8 @@ class FormHelper {
*/ */
public function valuesChanged($form, array $values) { public function valuesChanged($form, array $values) {
foreach (self::$valuesToCheck as $field_name) { foreach (self::$valuesToCheck as $field_name) {
if (isset($values[$field_name]) && $values[$field_name] != $form['simple_sitemap'][$field_name]['#default_value']) { if (!isset($form['simple_sitemap'][$field_name]['#default_value'])
|| (isset($values[$field_name]) && $values[$field_name] != $form['simple_sitemap'][$field_name]['#default_value'])) {
return TRUE; return TRUE;
} }
} }
......