Commit 828caaa0 authored by gbyte.co's avatar gbyte.co

Clean up some

parent 4610a745
......@@ -11,9 +11,17 @@ class Batch {
use StringTranslationTrait;
/**
* @var array
*/
private $batch;
/**
* @var array
*/
private $batchInfo;
const BATCH_TITLE = 'Generating XML sitemap';
const BATCH_INIT_MESSAGE = 'Initializing batch...';
const BATCH_ERROR_MESSAGE = 'An error has occurred. This may result in an incomplete XML sitemap.';
const BATCH_PROGRESS_MESSAGE = 'Processing @current out of @total link types.';
......@@ -23,7 +31,7 @@ class Batch {
*/
public function __construct() {
$this->batch = [
'title' => $this->t('Generating XML sitemap'),
'title' => $this->t(self::BATCH_TITLE),
'init_message' => $this->t(self::BATCH_INIT_MESSAGE),
'error_message' => $this->t(self::BATCH_ERROR_MESSAGE),
'progress_message' => $this->t(self::BATCH_PROGRESS_MESSAGE),
......@@ -34,9 +42,9 @@ class Batch {
}
/**
* @param $batch_info
* @param array $batch_info
*/
public function setBatchInfo($batch_info) {
public function setBatchInfo(array $batch_info) {
$this->batchInfo = $batch_info;
}
......@@ -72,7 +80,7 @@ class Batch {
case 'nobatch':
// Call each batch operation the way the Drupal batch API would do, but
// within one process (so in fact not using batch API here, just
// mimicking it to avoid code duplication.
// mimicking it to avoid code duplication).
$context = [];
foreach ($this->batch['operations'] as $i => $operation) {
$operation[1][] = &$context;
......@@ -89,7 +97,7 @@ class Batch {
* @param string $processing_method
* @param array $data
*/
public function addOperation($processing_method, $data) {
public function addOperation($processing_method, array $data) {
$this->batch['operations'][] = [
__CLASS__ . '::' . $processing_method, [$data, $this->batchInfo],
];
......@@ -101,8 +109,10 @@ class Batch {
* @param array $entity_info
* @param array $batch_info
* @param array &$context
*
* @see https://api.drupal.org/api/drupal/core!includes!form.inc/group/batch/8
*/
public static function generateBundleUrls($entity_info, $batch_info, &$context) {
public static function generateBundleUrls(array $entity_info, array $batch_info, &$context) {
\Drupal::service('simple_sitemap.batch_url_generator')
->setContext($context)
->setBatchInfo($batch_info)
......@@ -110,7 +120,7 @@ class Batch {
}
/**
* Batch function which generates urls to custom paths.
* Batch callback function which generates urls to custom paths.
*
* @param array $custom_paths
* @param array $batch_info
......@@ -118,7 +128,7 @@ class Batch {
*
* @see https://api.drupal.org/api/drupal/core!includes!form.inc/group/batch/8
*/
public static function generateCustomUrls($custom_paths, $batch_info, &$context) {
public static function generateCustomUrls(array $custom_paths, array $batch_info, &$context) {
\Drupal::service('simple_sitemap.batch_url_generator')
->setContext($context)
->setBatchInfo($batch_info)
......
......@@ -15,8 +15,7 @@ use Drupal\Core\Path\PathValidator;
use Drupal\Core\Entity\Query\QueryFactory;
/**
* Class BatchUrlGenerator.
*
* Class BatchUrlGenerator
* @package Drupal\simple_sitemap\Batch
*/
class BatchUrlGenerator {
......@@ -29,30 +28,75 @@ class BatchUrlGenerator {
const REGENERATION_FINISHED_MESSAGE = "The <a href='@url' target='_blank'>XML sitemap</a> has been regenerated for all languages.";
const REGENERATION_FINISHED_ERROR_MESSAGE = 'The sitemap generation finished with an error.';
/**
* @var \Drupal\simple_sitemap\Simplesitemap
*/
protected $generator;
/**
* @var \Drupal\simple_sitemap\SitemapGenerator
*/
protected $sitemapGenerator;
/**
* @var \Drupal\Core\Language\LanguageManagerInterface
*/
protected $languageManager;
/**
* @var \Drupal\Core\Language\LanguageInterface[]
*/
protected $languages;
/**
* @var string
*/
protected $defaultLanguageId;
/**
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* @var \Drupal\Core\Path\PathValidator
*/
protected $pathValidator;
/**
* @var \Drupal\Core\Entity\Query\QueryFactory
*/
protected $entityQuery;
/**
* @var \Drupal\simple_sitemap\Logger
*/
protected $logger;
/**
* @var \Drupal\Core\Entity\EntityInterface|null
*/
protected $anonUser;
/**
* @var array
*/
protected $context;
/**
* @var array
*/
protected $batchInfo;
/**
* BatchUrlGenerator constructor.
*
* @param $generator
* @param $sitemap_generator
* @param $language_manager
* @param $entity_type_manager
* @param $path_validator
* @param $entity_query
* @param $logger
* @param \Drupal\simple_sitemap\Simplesitemap $generator
* @param \Drupal\simple_sitemap\SitemapGenerator $sitemap_generator
* @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* @param \Drupal\Core\Path\PathValidator $path_validator
* @param \Drupal\Core\Entity\Query\QueryFactory $entity_query
* @param \Drupal\simple_sitemap\Logger $logger
*/
public function __construct(
Simplesitemap $generator,
......@@ -86,10 +130,10 @@ class BatchUrlGenerator {
}
/**
* @param $batch_info
* @param array $batch_info
* @return $this
*/
public function setBatchInfo($batch_info) {
public function setBatchInfo(array $batch_info) {
$this->batchInfo = $batch_info;
return $this;
}
......@@ -99,7 +143,7 @@ class BatchUrlGenerator {
*
* @param array $entity_info
*/
public function generateBundleUrls($entity_info) {
public function generateBundleUrls(array $entity_info) {
foreach ($this->getBatchIterationEntities($entity_info) as $entity_id => $entity) {
......@@ -155,7 +199,7 @@ class BatchUrlGenerator {
*
* @param array $custom_paths
*/
public function generateCustomUrls($custom_paths) {
public function generateCustomUrls(array $custom_paths) {
$custom_paths = $this->getBatchIterationCustomPaths($custom_paths);
......@@ -205,7 +249,7 @@ class BatchUrlGenerator {
}
/**
* @param $path
* @param string $path
* @return bool
*/
protected function pathProcessed($path) {
......@@ -249,10 +293,10 @@ class BatchUrlGenerator {
}
/**
* @param $custom_paths
* @param array $custom_paths
* @return mixed
*/
private function getBatchIterationCustomPaths($custom_paths) {
private function getBatchIterationCustomPaths(array $custom_paths) {
if ($this->needsInitialization()) {
$this->initializeBatch(count($custom_paths));
......
......@@ -10,8 +10,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Drupal\simple_sitemap\Simplesitemap;
/**
* Class SimplesitemapController.
*
* Class SimplesitemapController
* @package Drupal\simple_sitemap\Controller
*/
class SimplesitemapController extends ControllerBase {
......
......@@ -9,8 +9,7 @@ use Drupal\Core\Session\AccountProxyInterface;
use Drupal\Core\Form\FormState;
/**
* Class FormHelper.
*
* Class FormHelper
* @package Drupal\simple_sitemap\Form
*/
class FormHelper {
......@@ -20,15 +19,49 @@ class FormHelper {
const PRIORITY_HIGHEST = 10;
const PRIORITY_DIVIDER = 10;
/**
* @var \Drupal\simple_sitemap\Simplesitemap
*/
private $generator;
/**
* @var \Drupal\simple_sitemap\EntityHelper
*/
private $entityHelper;
/**
* @var \Drupal\Core\Session\AccountProxyInterface
*/
private $currentUser;
/**
* @var \Drupal\Core\Form\FormState
*/
private $formState;
/**
* @var bool
*/
public $alteringForm = TRUE;
/**
* @var string|null
*/
public $entityCategory = NULL;
/**
* @var string
*/
public $entityTypeId;
/**
* @var string
*/
public $bundleName;
/**
* @var string
*/
public $instanceId;
private static $allowedFormOperations = [
......@@ -61,7 +94,7 @@ class FormHelper {
}
/**
* @param $form_state
* @param \Drupal\Core\Form\FormState $form_state
* @return $this
*/
public function processForm(FormState $form_state) {
......@@ -74,7 +107,7 @@ class FormHelper {
}
/**
* @param $entity_category
* @param string $entity_category
* @return $this
*/
public function setEntityCategory($entity_category) {
......@@ -83,7 +116,7 @@ class FormHelper {
}
/**
* @param $entity_type_id
* @param string $entity_type_id
* @return $this
*/
public function setEntityTypeId($entity_type_id) {
......@@ -92,7 +125,7 @@ class FormHelper {
}
/**
* @param $bundle_name
* @param string $bundle_name
* @return $this
*/
public function setBundleName($bundle_name) {
......@@ -101,7 +134,7 @@ class FormHelper {
}
/**
* @param $instance_id
* @param string $instance_id
* @return $this
*/
public function setInstanceId($instance_id) {
......@@ -138,7 +171,7 @@ class FormHelper {
}
/**
* @param $form_fragment
* @param array $form_fragment
*/
public function displayRegenerateNow(&$form_fragment) {
$form_fragment['simple_sitemap_regenerate_now'] = [
......
......@@ -5,8 +5,7 @@ namespace Drupal\simple_sitemap\Form;
use Drupal\Core\Form\FormStateInterface;
/**
* Class SimplesitemapCustomLinksForm.
*
* Class SimplesitemapCustomLinksForm
* @package Drupal\simple_sitemap\Form
*/
class SimplesitemapCustomLinksForm extends SimplesitemapFormBase {
......
......@@ -5,8 +5,7 @@ namespace Drupal\simple_sitemap\Form;
use Drupal\Core\Form\FormStateInterface;
/**
* Class SimplesitemapEntitiesForm.
*
* Class SimplesitemapEntitiesForm
* @package Drupal\simple_sitemap\Form
*/
class SimplesitemapEntitiesForm extends SimplesitemapFormBase {
......
......@@ -9,15 +9,29 @@ use Drupal\simple_sitemap\Simplesitemap;
use Drupal\Core\Path\PathValidator;
/**
* Class SimplesitemapFormBase.
*
* Class SimplesitemapFormBase
* @package Drupal\simple_sitemap\Form
*/
abstract class SimplesitemapFormBase extends ConfigFormBase {
/**
* @var \Drupal\simple_sitemap\Simplesitemap
*/
protected $generator;
/**
* @var \Drupal\simple_sitemap\Form\FormHelper
*/
protected $formHelper;
/**
* @var \Drupal\simple_sitemap\EntityHelper
*/
protected $entityHelper;
/**
* @var \Drupal\Core\Path\PathValidator
*/
protected $pathValidator;
/**
......
......@@ -6,12 +6,14 @@ use Drupal\Core\Form\FormStateInterface;
use Drupal\Component\Utility\UrlHelper;
/**
* Class SimplesitemapSettingsForm.
*
* Class SimplesitemapSettingsForm
* @package Drupal\simple_sitemap\Form
*/
class SimplesitemapSettingsForm extends SimplesitemapFormBase {
/**
* @var array
*/
private $formSettings = [
'max_links',
'cron_generate',
......
......@@ -7,12 +7,13 @@ use Drupal\Core\Session\AccountProxyInterface;
use Psr\Log\LoggerInterface;
/**
* Class Logger.
*
* Class Logger
* @package Drupal\simple_sitemap
*/
class Logger {
use StringTranslationTrait;
/*
* Can be debug/info/notice/warning/error.
*/
......@@ -23,8 +24,6 @@ class Logger {
*/
const DISPLAY_MESSAGE_TYPE_DEFAULT = 'status';
use StringTranslationTrait;
/**
* @var \Psr\Log\LoggerInterface
*/
......
......@@ -11,19 +11,49 @@ use Drupal\Core\Config\ConfigFactory;
use Drupal\Core\Datetime\DateFormatter;
/**
* Class Simplesitemap.
*
* Class Simplesitemap
* @package Drupal\simple_sitemap
*/
class Simplesitemap {
/**
* @var \Drupal\simple_sitemap\SitemapGenerator
*/
private $sitemapGenerator;
/**
* @var \Drupal\simple_sitemap\EntityHelper
*/
private $entityHelper;
/**
* @var \Drupal\Core\Config\ConfigFactory
*/
private $configFactory;
/**
* @var \Drupal\Core\Database\Connection
*/
private $db;
/**
* @var \Drupal\Core\Entity\Query\QueryFactory
*/
private $entityQuery;
/**
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
private $entityTypeManager;
/**
* @var \Drupal\Core\Path\PathValidator
*/
private $pathValidator;
/**
* @var array
*/
private static $allowed_link_settings = [
'entity' => ['index', 'priority'],
'custom' => ['priority'],
......@@ -205,11 +235,12 @@ class Simplesitemap {
* @param string|null $bundle_name
*
* @return array|false
* Array of sitemap settings or array of entity types with their settings.
* Array of sitemap settings for an entity bundle, a non-bundle entity type
* or for all entity types and their bundles.
* False if entity type does not exist.
*/
public function getBundleSettings($entity_type_id = NULL, $bundle_name = NULL) {
if (!is_null($entity_type_id)) {
if (null !== $entity_type_id) {
$bundle_name = empty($bundle_name) ? $entity_type_id : $bundle_name;
$settings = $this->configFactory
->get("simple_sitemap.bundle_settings.$entity_type_id.$bundle_name")
......
......@@ -9,8 +9,7 @@ use Drupal\Core\Extension\ModuleHandler;
use Drupal\Core\Language\LanguageManagerInterface;
/**
* Class SitemapGenerator.
*
* Class SitemapGenerator
* @package Drupal\simple_sitemap
*/
class SitemapGenerator {
......@@ -21,13 +20,44 @@ class SitemapGenerator {
const XMLNS_XHTML = 'http://www.w3.org/1999/xhtml';
const GENERATED_BY = 'Generated by the Simple XML sitemap Drupal module: https://drupal.org/project/simple_sitemap.';
/**
* @var \Drupal\simple_sitemap\Batch\Batch
*/
private $batch;
/**
* @var \Drupal\simple_sitemap\EntityHelper
*/
private $entityHelper;
/**
* @var \Drupal\Core\Database\Connection
*/
private $db;
/**
* @var \Drupal\Core\Extension\ModuleHandler
*/
private $moduleHandler;
/**
* @var string
*/
private $defaultLanguageId;
/**
* @var string
*/
private $generateFrom = 'form';
/**
* @var bool
*/
private $isHreflangSitemap;
/**
* @var \Drupal\simple_sitemap\Simplesitemap
*/
private $generator;
/**
......
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