Commit 1bdd4722 authored by gbyte.co's avatar gbyte.co

Resolve some todos and clean up

parent 250f4b1c
...@@ -40,6 +40,7 @@ services: ...@@ -40,6 +40,7 @@ services:
- '@simple_sitemap.manager' - '@simple_sitemap.manager'
- '@state' - '@state'
- '@simple_sitemap.queue' - '@simple_sitemap.queue'
- '@simple_sitemap.logger'
simple_sitemap.queue: simple_sitemap.queue:
class: Drupal\simple_sitemap\Queue\SimplesitemapQueue class: Drupal\simple_sitemap\Queue\SimplesitemapQueue
......
...@@ -2,7 +2,10 @@ ...@@ -2,7 +2,10 @@
namespace Drupal\simple_sitemap\Form; namespace Drupal\simple_sitemap\Form;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\FormStateInterface;
use Drupal\simple_sitemap\Simplesitemap;
use Drupal\Core\Path\PathValidator;
/** /**
* Class SimplesitemapCustomLinksForm * Class SimplesitemapCustomLinksForm
...@@ -10,6 +13,40 @@ use Drupal\Core\Form\FormStateInterface; ...@@ -10,6 +13,40 @@ use Drupal\Core\Form\FormStateInterface;
*/ */
class SimplesitemapCustomLinksForm extends SimplesitemapFormBase { class SimplesitemapCustomLinksForm extends SimplesitemapFormBase {
/**
* @var \Drupal\Core\Path\PathValidator
*/
protected $pathValidator;
/**
* SimplesitemapCustomLinksForm constructor.
* @param \Drupal\simple_sitemap\Simplesitemap $generator
* @param \Drupal\simple_sitemap\Form\FormHelper $form_helper
* @param \Drupal\Core\Path\PathValidator $path_validator
*/
public function __construct(
Simplesitemap $generator,
FormHelper $form_helper,
PathValidator $path_validator
) {
parent::__construct(
$generator,
$form_helper
);
$this->pathValidator = $path_validator;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('simple_sitemap.generator'),
$container->get('simple_sitemap.form_helper'),
$container->get('path.validator')
);
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
......
...@@ -2,7 +2,10 @@ ...@@ -2,7 +2,10 @@
namespace Drupal\simple_sitemap\Form; namespace Drupal\simple_sitemap\Form;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\FormStateInterface;
use Drupal\simple_sitemap\Simplesitemap;
use Drupal\simple_sitemap\EntityHelper;
/** /**
* Class SimplesitemapEntitiesForm * Class SimplesitemapEntitiesForm
...@@ -10,6 +13,40 @@ use Drupal\Core\Form\FormStateInterface; ...@@ -10,6 +13,40 @@ use Drupal\Core\Form\FormStateInterface;
*/ */
class SimplesitemapEntitiesForm extends SimplesitemapFormBase { class SimplesitemapEntitiesForm extends SimplesitemapFormBase {
/**
* @var \Drupal\simple_sitemap\EntityHelper
*/
protected $entityHelper;
/**
* SimplesitemapEntitiesForm constructor.
* @param \Drupal\simple_sitemap\Simplesitemap $generator
* @param \Drupal\simple_sitemap\Form\FormHelper $form_helper
* @param \Drupal\simple_sitemap\EntityHelper $entity_helper
*/
public function __construct(
Simplesitemap $generator,
FormHelper $form_helper,
EntityHelper $entity_helper
) {
parent::__construct(
$generator,
$form_helper
);
$this->entityHelper = $entity_helper;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('simple_sitemap.generator'),
$container->get('simple_sitemap.form_helper'),
$container->get('simple_sitemap.entity_helper')
);
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
......
...@@ -2,12 +2,9 @@ ...@@ -2,12 +2,9 @@
namespace Drupal\simple_sitemap\Form; namespace Drupal\simple_sitemap\Form;
use Drupal\simple_sitemap\EntityHelper;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Form\ConfigFormBase; use Drupal\Core\Form\ConfigFormBase;
use Drupal\simple_sitemap\Simplesitemap; use Drupal\simple_sitemap\Simplesitemap;
use Drupal\Core\Path\PathValidator;
use Drupal\Core\Language\LanguageManagerInterface;
/** /**
* Class SimplesitemapFormBase * Class SimplesitemapFormBase
...@@ -25,41 +22,17 @@ abstract class SimplesitemapFormBase extends ConfigFormBase { ...@@ -25,41 +22,17 @@ abstract class SimplesitemapFormBase extends ConfigFormBase {
*/ */
protected $formHelper; protected $formHelper;
/**
* @var \Drupal\simple_sitemap\EntityHelper
*/
protected $entityHelper;
/**
* @var \Drupal\Core\Path\PathValidator
*/
protected $pathValidator;
/**
* @var \Drupal\Core\Language\LanguageManagerInterface
*/
protected $languageManager;
/** /**
* SimplesitemapFormBase constructor. * SimplesitemapFormBase constructor.
* @param \Drupal\simple_sitemap\Simplesitemap $generator * @param \Drupal\simple_sitemap\Simplesitemap $generator
* @param \Drupal\simple_sitemap\Form\FormHelper $form_helper * @param \Drupal\simple_sitemap\Form\FormHelper $form_helper
* @param \Drupal\simple_sitemap\EntityHelper $entity_helper
* @param \Drupal\Core\Path\PathValidator $path_validator
* @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
*/ */
public function __construct( public function __construct(
Simplesitemap $generator, Simplesitemap $generator,
FormHelper $form_helper, FormHelper $form_helper
EntityHelper $entity_helper,
PathValidator $path_validator,
LanguageManagerInterface $language_manager
) { ) {
$this->generator = $generator; $this->generator = $generator;
$this->formHelper = $form_helper; $this->formHelper = $form_helper;
$this->entityHelper = $entity_helper;
$this->pathValidator = $path_validator;
$this->languageManager = $language_manager;
} }
/** /**
...@@ -68,10 +41,7 @@ abstract class SimplesitemapFormBase extends ConfigFormBase { ...@@ -68,10 +41,7 @@ abstract class SimplesitemapFormBase extends ConfigFormBase {
public static function create(ContainerInterface $container) { public static function create(ContainerInterface $container) {
return new static( return new static(
$container->get('simple_sitemap.generator'), $container->get('simple_sitemap.generator'),
$container->get('simple_sitemap.form_helper'), $container->get('simple_sitemap.form_helper')
$container->get('simple_sitemap.entity_helper'),
$container->get('path.validator'),
$container->get('language_manager')
); );
} }
......
...@@ -2,8 +2,12 @@ ...@@ -2,8 +2,12 @@
namespace Drupal\simple_sitemap\Form; namespace Drupal\simple_sitemap\Form;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\FormStateInterface;
use Drupal\simple_sitemap\Simplesitemap;
use Drupal\Component\Utility\UrlHelper; use Drupal\Component\Utility\UrlHelper;
use Drupal\Core\Language\LanguageManager;
use Drupal\Core\Database\Connection;
/** /**
* Class SimplesitemapSettingsForm * Class SimplesitemapSettingsForm
...@@ -11,6 +15,49 @@ use Drupal\Component\Utility\UrlHelper; ...@@ -11,6 +15,49 @@ use Drupal\Component\Utility\UrlHelper;
*/ */
class SimplesitemapSettingsForm extends SimplesitemapFormBase { class SimplesitemapSettingsForm extends SimplesitemapFormBase {
/**
* @var \Drupal\Core\Language\LanguageManagerInterface
*/
protected $languageManager;
/**
* @var \Drupal\Core\Database\Connection
*/
protected $db;
/**
* SimplesitemapSettingsForm constructor.
* @param \Drupal\simple_sitemap\Simplesitemap $generator
* @param \Drupal\simple_sitemap\Form\FormHelper $form_helper
* @param \Drupal\Core\Language\LanguageManager $language_manager
* @param \Drupal\Core\Database\Connection $database
*/
public function __construct(
Simplesitemap $generator,
FormHelper $form_helper,
LanguageManager $language_manager,
Connection $database
) {
parent::__construct(
$generator,
$form_helper
);
$this->languageManager = $language_manager;
$this->db = $database;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('simple_sitemap.generator'),
$container->get('simple_sitemap.form_helper'),
$container->get('language_manager'),
$container->get('database')
);
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
...@@ -282,7 +329,7 @@ class SimplesitemapSettingsForm extends SimplesitemapFormBase { ...@@ -282,7 +329,7 @@ class SimplesitemapSettingsForm extends SimplesitemapFormBase {
* 2: Instance is published but is being regenerated * 2: Instance is published but is being regenerated
*/ */
protected function fetchSitemapInstanceStatuses() { protected function fetchSitemapInstanceStatuses() {
$results = \Drupal::database() //todo DI $results = $this->db
->query('SELECT type, status FROM {simple_sitemap} GROUP BY type, status') ->query('SELECT type, status FROM {simple_sitemap} GROUP BY type, status')
->fetchAll(); ->fetchAll();
......
...@@ -298,6 +298,6 @@ abstract class SitemapGeneratorBase extends SimplesitemapPluginBase implements S ...@@ -298,6 +298,6 @@ abstract class SitemapGeneratorBase extends SimplesitemapPluginBase implements S
*/ */
protected function getCustomBaseUrl() { protected function getCustomBaseUrl() {
$customBaseUrl = $this->settings['base_url']; $customBaseUrl = $this->settings['base_url'];
return !empty($customBaseUrl) ? $customBaseUrl : $GLOBALS['base_url']; //todo use service return !empty($customBaseUrl) ? $customBaseUrl : $GLOBALS['base_url'];
} }
} }
...@@ -93,8 +93,6 @@ class CustomUrlGenerator extends EntityUrlGeneratorBase { ...@@ -93,8 +93,6 @@ class CustomUrlGenerator extends EntityUrlGeneratorBase {
/** /**
* @inheritdoc * @inheritdoc
*
* @todo Support sitemap variants.
*/ */
public function getDataSets() { public function getDataSets() {
$this->includeImages = $this->generator->getSetting('custom_links_include_images', FALSE); $this->includeImages = $this->generator->getSetting('custom_links_include_images', FALSE);
......
...@@ -45,7 +45,6 @@ trait BatchTrait { ...@@ -45,7 +45,6 @@ trait BatchTrait {
$this->batch =& batch_get(); $this->batch =& batch_get();
$this->batch['progressive'] = FALSE; $this->batch['progressive'] = FALSE;
drush_log($this->batch['init_message'], 'status');
drush_backend_batch_process(); drush_backend_batch_process();
return TRUE; return TRUE;
} }
...@@ -83,15 +82,11 @@ trait BatchTrait { ...@@ -83,15 +82,11 @@ trait BatchTrait {
* @return bool * @return bool
* *
* @see https://api.drupal.org/api/drupal/core!includes!form.inc/group/batch/8 * @see https://api.drupal.org/api/drupal/core!includes!form.inc/group/batch/8
*
* @todo Display success/failure message in Drush > 9.
*/ */
public static function finishGeneration($success, $results, $operations) { public static function finishGeneration($success, $results, $operations) {
if ($success) { if ($success) {
\Drupal::service('simple_sitemap.logger') \Drupal::service('simple_sitemap.logger')
->m('The XML sitemaps have been regenerated.') ->m('The XML sitemaps have been regenerated.')
// ['@url' => $this->sitemapGenerator->getCustomBaseUrl() . '/sitemap.xml']) //todo: Use actual base URL for message.
->display('status')
->log('info'); ->log('info');
} }
else { else {
......
...@@ -7,6 +7,7 @@ use Drupal\simple_sitemap\Plugin\simple_sitemap\SitemapGenerator\SitemapGenerato ...@@ -7,6 +7,7 @@ use Drupal\simple_sitemap\Plugin\simple_sitemap\SitemapGenerator\SitemapGenerato
use Drupal\simple_sitemap\SimplesitemapSettings; use Drupal\simple_sitemap\SimplesitemapSettings;
use Drupal\simple_sitemap\SimplesitemapManager; use Drupal\simple_sitemap\SimplesitemapManager;
use Drupal\Core\State\State; use Drupal\Core\State\State;
use Drupal\simple_sitemap\Logger;
class QueueWorker { class QueueWorker {
...@@ -35,6 +36,11 @@ class QueueWorker { ...@@ -35,6 +36,11 @@ class QueueWorker {
*/ */
protected $queue; protected $queue;
/**
* @var \Drupal\simple_sitemap\Logger
*/
protected $logger;
/** /**
* @var string|null * @var string|null
*/ */
...@@ -81,15 +87,18 @@ class QueueWorker { ...@@ -81,15 +87,18 @@ class QueueWorker {
* @param \Drupal\simple_sitemap\SimplesitemapManager $manager * @param \Drupal\simple_sitemap\SimplesitemapManager $manager
* @param \Drupal\Core\State\State $state * @param \Drupal\Core\State\State $state
* @param \Drupal\simple_sitemap\Queue\SimplesitemapQueue $element_queue * @param \Drupal\simple_sitemap\Queue\SimplesitemapQueue $element_queue
* @param \Drupal\simple_sitemap\Logger $logger
*/ */
public function __construct(SimplesitemapSettings $settings, public function __construct(SimplesitemapSettings $settings,
SimplesitemapManager $manager, SimplesitemapManager $manager,
State $state, State $state,
SimplesitemapQueue $element_queue) { SimplesitemapQueue $element_queue,
Logger $logger) {
$this->settings = $settings; $this->settings = $settings;
$this->manager = $manager; $this->manager = $manager;
$this->state = $state; $this->state = $state;
$this->queue = $element_queue; $this->queue = $element_queue;
$this->logger = $logger;
} }
/** /**
......
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