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

Streamline settings forms

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