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

Resolve some todos and clean up

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