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

Fix priority setting not showing for atomic entity types on sitemap entities page

parent 3b64c574
......@@ -10,68 +10,54 @@
attach: function(context, settings) {
var allEntities = settings.simple_sitemap.all_entities;
var atomicEntities = settings.simple_sitemap.atomic_entities;
var initiallyChecked = [];
var removingSettingsWarning = Drupal.t("<strong>Warning:</strong> This entity type's sitemap settings including per-entity overrides will be deleted after hitting <em>Save</em>.");
// On load.
// Hide the 'Regenerate sitemap' field to only display it if settings have changed.
$('.form-item-simple-sitemap-regenerate-now').hide();
// Get all entities that are enabled on form load.
$.each(allEntities, function(index, value) {
var enabledId = '#edit-' + value + '-enabled';
if ($(context).find(enabledId).is(':checked')) {
initiallyChecked.push(value);
}
});
// Show priority settings if atomic entity enabled on form load.
$.each(atomicEntities, function(index, value) {
var enabledId = '#edit-' + value + '-enabled';
var priorityId = '.form-item-' + value + '-simple-sitemap-priority';
if ($(context).find(enabledId).is(':checked')) {
// Show 'Priority' field if 'Index sitemap' is ticked.
$(priorityId).show();
}
else { // Hide 'Priority' field if 'Index sitemap' is empty.
$(priorityId).hide();
}
});
// On load: hide all warning messages.
$('#warning-' + value).hide();
// On change.
$.each(allEntities, function(index, value) {
// On change: Show or hide warning message dependent on 'enabled' checkbox.
var enabledId = '#edit-' + value + '-enabled';
$(enabledId).change(function() {
if ($(context).find(enabledId).is(':checked')) {
$('#warning-' + value).remove();
if ($(enabledId).is(':checked')) {
$('#warning-' + value).hide();
}
else {
if ($.inArray(value, initiallyChecked) != -1) {
$('.form-item-' + value + '-enabled')
.append("<div id='warning-" + value + "'>"
+ removingSettingsWarning + "</div>");
}
$('#warning-' + value).show();
}
// Show 'Regenerate sitemap' field if setting has changed.
// Show 'Regenerate sitemap' field if 'enabled' setting has changed.
$('.form-item-simple-sitemap-regenerate-now').show();
});
});
// Show priority settings if atomic entity enabled on form load.
$.each(atomicEntities, function(index, value) {
var enabledId = '#edit-' + value + '-enabled';
var priorityId = '.form-item-' + value + '-simple-sitemap-priority';
// On load: Show or hide priority setting dependent on 'enabled' checkbox.
if ($(enabledId).is(':checked')) {
$(priorityId).show();
}
else {
$(priorityId).hide();
}
// On change: Show or hide priority setting dependent on 'enabled' checkbox.
$(enabledId).change(function() {
if ($(context).find(enabledId).is(':checked')) {
// Show 'Priority' field if 'Index sitemap' is ticked.
if ($(enabledId).is(':checked')) {
$(priorityId).show();
}
else { // Hide 'Priority' field if 'Index sitemap' is empty.
else {
$(priorityId).hide();
}
});
// Show 'Regenerate sitemap' field if setting has changed.
// Show 'Regenerate sitemap' field if 'priority' setting has changed.
$(priorityId).change(function() {
$('.form-item-simple-sitemap-regenerate-now').show();
});
......
......@@ -54,6 +54,11 @@ class SimplesitemapEntitiesForm extends SimplesitemapFormBase {
'#description' => $this->t('Sitemap settings for this entity type can be set on its bundle pages and overridden on its entity pages.'),
'#default_value' => $this->generator->entityTypeIsEnabled($entity_type_id),
];
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-$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'][] = str_replace('_', '-', $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.');
......
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