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

Streamline settings forms

parent 3f70f2d4
......@@ -168,7 +168,7 @@ class Batch {
$url_object = $entity->getUrlObject();
break;
default: // Loading url object for other entities.
$url_object = $entity->toUrl();
$url_object = $entity->toUrl(); //todo: file entity type does not have a canonical url and breaks generation, hopefully fixed in https://www.drupal.org/node/2402533
}
// Do not include external paths.
......
......@@ -2,14 +2,13 @@
namespace Drupal\simple_sitemap\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\simple_sitemap\Form;
/**
* SimplesitemapCustomLinksFrom
*/
class SimplesitemapCustomLinksForm extends ConfigFormBase {
class SimplesitemapCustomLinksForm extends SimplesitemapFormBase {
/**
* {@inheritdoc}
......@@ -18,13 +17,6 @@ class SimplesitemapCustomLinksForm extends ConfigFormBase {
return 'simple_sitemap_custom_links_form';
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return ['simple_sitemap.settings_custom'];
}
/**
* {@inheritdoc}
*/
......@@ -43,6 +35,7 @@ class SimplesitemapCustomLinksForm extends ConfigFormBase {
'#title' => $this->t('Custom links'),
'#type' => 'fieldset',
'#markup' => '<p>' . $this->t('Add custom internal drupal paths to the XML sitemap.') . '</p>',
'#prefix' => $this->getDonationLink(),
];
$form['simple_sitemap_custom']['custom_links'] = [
......
......@@ -2,15 +2,12 @@
namespace Drupal\simple_sitemap\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\simple_sitemap\Simplesitemap;
use Drupal\simple_sitemap\Form;
/**
* SimplesitemapSettingsFrom
*/
class SimplesitemapEntitiesForm extends ConfigFormBase {
class SimplesitemapEntitiesForm extends SimplesitemapFormBase {
/**
* {@inheritdoc}
......@@ -19,13 +16,6 @@ class SimplesitemapEntitiesForm extends ConfigFormBase {
return 'simple_sitemap_entities_form';
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return ['simple_sitemap.settings'];
}
/**
* {@inheritdoc}
*/
......@@ -33,6 +23,8 @@ class SimplesitemapEntitiesForm extends ConfigFormBase {
$generator = \Drupal::service('simple_sitemap.generator');
$form['simple_sitemap_entities']['#prefix'] = $this->getDonationLink();
$form['simple_sitemap_entities']['entities'] = [
'#title' => $this->t('Sitemap entities'),
'#type' => 'fieldset',
......
<?php
namespace Drupal\simple_sitemap\Form;
use Drupal\Core\Form\ConfigFormBase;
/**
* SimplesitemapFormBase
*/
abstract class SimplesitemapFormBase extends ConfigFormBase {
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return ['simple_sitemap.settings'];
}
protected function getDonationLink() {
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>";
}
}
......@@ -2,13 +2,12 @@
namespace Drupal\simple_sitemap\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
/**
* SimplesitemapSettingsFrom
*/
class SimplesitemapSettingsForm extends ConfigFormBase {
class SimplesitemapSettingsForm extends SimplesitemapFormBase {
private $form_settings = [
'max_links',
......@@ -25,13 +24,6 @@ class SimplesitemapSettingsForm extends ConfigFormBase {
return 'simple_sitemap_settings_form';
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return ['simple_sitemap.settings'];
}
/**
* {@inheritdoc}
*/
......@@ -39,7 +31,7 @@ class SimplesitemapSettingsForm extends ConfigFormBase {
$generator = \Drupal::service('simple_sitemap.generator');
$form['simple_sitemap_settings']['#prefix'] = "<div class='description'>" .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>";
$form['simple_sitemap_settings']['#prefix'] = $this->getDonationLink();
$form['simple_sitemap_settings']['regenerate'] = [
'#title' => $this->t('Regenerate sitemap'),
......@@ -68,7 +60,7 @@ class SimplesitemapSettingsForm extends ConfigFormBase {
$form['simple_sitemap_settings']['advanced'] = [
'#title' => $this->t('Advanced settings'),
'#type' => 'details',
'#type' => 'fieldset',
];
$form['simple_sitemap_settings']['advanced']['remove_duplicates'] = [
......@@ -104,6 +96,8 @@ class SimplesitemapSettingsForm extends ConfigFormBase {
'#required' => TRUE,
];
\Drupal::service('simple_sitemap.form')->displayRegenerateNow($form['simple_sitemap_settings']);
return parent::buildForm($form, $form_state);
}
......@@ -133,6 +127,11 @@ class SimplesitemapSettingsForm extends ConfigFormBase {
$generator->saveSetting($setting_name, $form_state->getValue($setting_name));
}
parent::submitForm($form, $form_state);
// Regenerate sitemaps according to user setting.
if ($form_state->getValue('simple_sitemap_regenerate_now')) {
$generator->generateSitemap();
}
}
public function generateSitemap(array &$form, FormStateInterface $form_state) {
......
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