From 9c657c654f60467f267da443e0d03783ad31f7c5 Mon Sep 17 00:00:00 2001 From: Pawel G Date: Sat, 1 Jun 2019 02:55:58 +0200 Subject: [PATCH] Clean up --- .../SimpleSitemapViewsController.php | 8 ++++- src/Form/FormHelper.php | 35 +++++++++++++++++++ src/Form/SimplesitemapCustomLinksForm.php | 2 +- src/Form/SimplesitemapEntitiesForm.php | 2 +- src/Form/SimplesitemapFormBase.php | 7 ---- src/Form/SimplesitemapSettingsForm.php | 21 ++--------- src/Form/SimplesitemapVariantsForm.php | 2 +- 7 files changed, 48 insertions(+), 29 deletions(-) diff --git a/modules/simple_sitemap_views/src/Controller/SimpleSitemapViewsController.php b/modules/simple_sitemap_views/src/Controller/SimpleSitemapViewsController.php index db66cab..b041d8a 100644 --- a/modules/simple_sitemap_views/src/Controller/SimpleSitemapViewsController.php +++ b/modules/simple_sitemap_views/src/Controller/SimpleSitemapViewsController.php @@ -2,6 +2,7 @@ namespace Drupal\simple_sitemap_views\Controller; +use Drupal\simple_sitemap\Form\FormHelper; use Symfony\Component\DependencyInjection\ContainerInterface; use Drupal\simple_sitemap_views\SimpleSitemapViews; use Drupal\Core\Controller\ControllerBase; @@ -80,7 +81,12 @@ class SimpleSitemapViewsController extends ControllerBase { } // Show information about indexed displays. - $build['indexed_displays'] = $table; + $build['simple_sitemap_views'] = [ + '#prefix' => FormHelper::getDonationText(), + '#title' => $this->t('Indexed view displays'), + '#type' => 'fieldset', + 'table' => $table, + ]; return $build; } diff --git a/src/Form/FormHelper.php b/src/Form/FormHelper.php index 5748eb5..32706ca 100644 --- a/src/Form/FormHelper.php +++ b/src/Form/FormHelper.php @@ -87,6 +87,20 @@ class FormHelper { 'never', ]; + protected static $cronIntervals = [ + 1, + 3, + 6, + 12, + 24, + 48, + 72, + 96, + 120, + 144, + 168, + ]; + /** * FormHelper constructor. * @param \Drupal\simple_sitemap\Simplesitemap $generator @@ -570,4 +584,25 @@ class FormHelper { public static function isValidChangefreq($changefreq) { return in_array($changefreq, self::$changefreqValues); } + + /** + * @return array + */ + public static function getCronIntervalOptions() { + /** @var \Drupal\Core\Datetime\DateFormatter $formatter */ + $formatter = \Drupal::service('date.formatter'); + $intervals = array_flip(self::$cronIntervals); + foreach ($intervals as $interval => &$label) { + $label = $formatter->formatInterval($interval * 60 * 60); + } + + return [0 => t('On every cron run')] + $intervals; + } + + /** + * @return string + */ + public static function getDonationText() { + return '
' . t('If you would like to say thanks and support the development of this module, a donation will be much appreciated.', ['@url' => 'https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=5AFYRSBLGSC3W']) . '
'; + } } diff --git a/src/Form/SimplesitemapCustomLinksForm.php b/src/Form/SimplesitemapCustomLinksForm.php index ead2e74..5af8439 100644 --- a/src/Form/SimplesitemapCustomLinksForm.php +++ b/src/Form/SimplesitemapCustomLinksForm.php @@ -63,7 +63,7 @@ class SimplesitemapCustomLinksForm extends SimplesitemapFormBase { '#title' => $this->t('Custom links'), '#type' => 'fieldset', '#markup' => '
' . $this->t('Add custom internal drupal paths to the XML sitemap.') . '
', - '#prefix' => $this->getDonationText(), + '#prefix' => FormHelper::getDonationText(), ]; $form['simple_sitemap_custom']['custom_links'] = [ diff --git a/src/Form/SimplesitemapEntitiesForm.php b/src/Form/SimplesitemapEntitiesForm.php index a1531bb..0210a87 100644 --- a/src/Form/SimplesitemapEntitiesForm.php +++ b/src/Form/SimplesitemapEntitiesForm.php @@ -59,7 +59,7 @@ class SimplesitemapEntitiesForm extends SimplesitemapFormBase { */ public function buildForm(array $form, FormStateInterface $form_state) { - $form['simple_sitemap_entities']['#prefix'] = $this->getDonationText(); + $form['simple_sitemap_entities']['#prefix'] = FormHelper::getDonationText(); $form['simple_sitemap_entities']['entities'] = [ '#title' => $this->t('Sitemap entities'), diff --git a/src/Form/SimplesitemapFormBase.php b/src/Form/SimplesitemapFormBase.php index e796a72..ac5118d 100644 --- a/src/Form/SimplesitemapFormBase.php +++ b/src/Form/SimplesitemapFormBase.php @@ -52,11 +52,4 @@ abstract class SimplesitemapFormBase extends ConfigFormBase { return ['simple_sitemap.settings']; } - /** - * - */ - protected function getDonationText() { - return '
' . $this->t('If you would like to say thanks and support the development of this module, a donation will be much appreciated.', ['@url' => 'https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=5AFYRSBLGSC3W']) . '
'; - } - } diff --git a/src/Form/SimplesitemapSettingsForm.php b/src/Form/SimplesitemapSettingsForm.php index 7c49727..92c780d 100644 --- a/src/Form/SimplesitemapSettingsForm.php +++ b/src/Form/SimplesitemapSettingsForm.php @@ -70,7 +70,7 @@ class SimplesitemapSettingsForm extends SimplesitemapFormBase { */ public function buildForm(array $form, FormStateInterface $form_state) { - $form['simple_sitemap_settings']['#prefix'] = $this->getDonationText(); + $form['simple_sitemap_settings']['#prefix'] = FormHelper::getDonationText(); $form['simple_sitemap_settings']['#attached']['library'][] = 'simple_sitemap/sitemapSettings'; $queue_worker = $this->generator->getQueueWorker(); @@ -222,24 +222,9 @@ class SimplesitemapSettingsForm extends SimplesitemapFormBase { '#title' => $this->t('Sitemap generation interval'), '#description' => $this->t('The sitemap will be generated according to this interval.'), '#default_value' => $this->generator->getSetting('cron_generate_interval', 0), - '#options' => [ - 0 => $this->t('On every cron run'), - 1 => $this->t('Once an hour'), - 3 => $this->t('Once every @hours hours', ['@hours' => 3]), - 6 => $this->t('Once every @hours hours', ['@hours' => 6]), - 12 => $this->t('Once every @hours hours', ['@hours' => 12]), - 24 => $this->t('Once a day'), - 48 => $this->t('Once every @days days', ['@days' => 48/24]), - 72 => $this->t('Once every @days days', ['@days' => 72/24]), - 96 => $this->t('Once every @days days', ['@days' => 96/24]), - 120 => $this->t('Once every @days days', ['@days' => 120/24]), - 144 => $this->t('Once every @days days', ['@days' => 144/24]), - 168 => $this->t('Once a week'), - ], + '#options' => FormHelper::getCronIntervalOptions(), '#states' => [ - 'visible' => [ - ':input[name="cron_generate"]' => ['checked' => TRUE], - ], + 'visible' => [':input[name="cron_generate"]' => ['checked' => TRUE]], ], ]; diff --git a/src/Form/SimplesitemapVariantsForm.php b/src/Form/SimplesitemapVariantsForm.php index 36114d5..324576f 100644 --- a/src/Form/SimplesitemapVariantsForm.php +++ b/src/Form/SimplesitemapVariantsForm.php @@ -27,7 +27,7 @@ class SimplesitemapVariantsForm extends SimplesitemapFormBase { '#title' => $this->t('Sitemap variants'), '#type' => 'fieldset', '#markup' => '
' . $this->t('Define sitemap variants. A sitemap variant is a sitemap instance of a certain type (specific sitemap generator and URL generators) accessible under a certain URL.
Each variant can have its own entity bundle settings (to be defined on bundle edit pages).') . '
', - '#prefix' => $this->getDonationText(), + '#prefix' => FormHelper::getDonationText(), ]; $form['simple_sitemap_variants']['variants'] = [ -- GitLab