Commit 250f4b1c authored by gbyte.co's avatar gbyte.co

Clean up

parent 6d0ba743
...@@ -109,7 +109,7 @@ abstract class SitemapGeneratorBase extends SimplesitemapPluginBase implements S ...@@ -109,7 +109,7 @@ abstract class SitemapGeneratorBase extends SimplesitemapPluginBase implements S
} }
/** /**
* @param $sitemap_variant * @param string $sitemap_variant
* @return $this * @return $this
*/ */
public function setSitemapVariant($sitemap_variant) { public function setSitemapVariant($sitemap_variant) {
...@@ -141,8 +141,7 @@ abstract class SitemapGeneratorBase extends SimplesitemapPluginBase implements S ...@@ -141,8 +141,7 @@ abstract class SitemapGeneratorBase extends SimplesitemapPluginBase implements S
} }
/** /**
* Returns the sitemap index for all sitemap chunks of this type. * @param array $chunk_info
*
* @return string * @return string
*/ */
protected function getIndexXml(array $chunk_info) { protected function getIndexXml(array $chunk_info) {
...@@ -214,12 +213,9 @@ abstract class SitemapGeneratorBase extends SimplesitemapPluginBase implements S ...@@ -214,12 +213,9 @@ abstract class SitemapGeneratorBase extends SimplesitemapPluginBase implements S
} }
/** /**
* Takes links along with their options and then generates and saves the
* sitemap.
*
* @param array $links * @param array $links
* All links with their multilingual versions and settings. * @return $this
* * @throws \Exception
*/ */
public function generate(array $links) { public function generate(array $links) {
$highest_id = $this->db->query('SELECT MAX(id) FROM {simple_sitemap}')->fetchField(); $highest_id = $this->db->query('SELECT MAX(id) FROM {simple_sitemap}')->fetchField();
...@@ -239,6 +235,7 @@ abstract class SitemapGeneratorBase extends SimplesitemapPluginBase implements S ...@@ -239,6 +235,7 @@ abstract class SitemapGeneratorBase extends SimplesitemapPluginBase implements S
} }
/** /**
* @return $this
* @throws \Exception * @throws \Exception
*/ */
public function generateIndex() { public function generateIndex() {
...@@ -269,6 +266,9 @@ abstract class SitemapGeneratorBase extends SimplesitemapPluginBase implements S ...@@ -269,6 +266,9 @@ abstract class SitemapGeneratorBase extends SimplesitemapPluginBase implements S
return $this; return $this;
} }
/**
* @return $this
*/
public function publish() { public function publish() {
$unpublished_chunk = $this->db->query('SELECT MAX(id) FROM {simple_sitemap} WHERE type = :type AND status = :status', [':type' => $this->sitemapVariant, ':status' => 0]) $unpublished_chunk = $this->db->query('SELECT MAX(id) FROM {simple_sitemap} WHERE type = :type AND status = :status', [':type' => $this->sitemapVariant, ':status' => 0])
->fetchField(); ->fetchField();
......
...@@ -2,11 +2,8 @@ ...@@ -2,11 +2,8 @@
namespace Drupal\simple_sitemap\Plugin\simple_sitemap\UrlGenerator; namespace Drupal\simple_sitemap\Plugin\simple_sitemap\UrlGenerator;
use Drupal\simple_sitemap\EntityHelper;
use Drupal\simple_sitemap\Logger; use Drupal\simple_sitemap\Logger;
use Drupal\simple_sitemap\Simplesitemap; use Drupal\simple_sitemap\Simplesitemap;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Extension\ModuleHandler; use Drupal\Core\Extension\ModuleHandler;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
...@@ -30,23 +27,15 @@ class ArbitraryUrlGenerator extends UrlGeneratorBase { ...@@ -30,23 +27,15 @@ class ArbitraryUrlGenerator extends UrlGeneratorBase {
* @param $plugin_id * @param $plugin_id
* @param $plugin_definition * @param $plugin_definition
* @param \Drupal\simple_sitemap\Simplesitemap $generator * @param \Drupal\simple_sitemap\Simplesitemap $generator
* @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* @param \Drupal\simple_sitemap\Logger $logger * @param \Drupal\simple_sitemap\Logger $logger
* @param \Drupal\simple_sitemap\EntityHelper $entityHelper
* @param \Drupal\Core\Extension\ModuleHandler $module_handler * @param \Drupal\Core\Extension\ModuleHandler $module_handler
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
*/ */
public function __construct( public function __construct(
array $configuration, array $configuration,
$plugin_id, $plugin_id,
$plugin_definition, $plugin_definition,
Simplesitemap $generator, Simplesitemap $generator,
LanguageManagerInterface $language_manager,
EntityTypeManagerInterface $entity_type_manager,
Logger $logger, Logger $logger,
EntityHelper $entityHelper,
ModuleHandler $module_handler ModuleHandler $module_handler
) { ) {
parent::__construct( parent::__construct(
...@@ -54,10 +43,7 @@ class ArbitraryUrlGenerator extends UrlGeneratorBase { ...@@ -54,10 +43,7 @@ class ArbitraryUrlGenerator extends UrlGeneratorBase {
$plugin_id, $plugin_id,
$plugin_definition, $plugin_definition,
$generator, $generator,
$language_manager, $logger
$entity_type_manager,
$logger,
$entityHelper
); );
$this->moduleHandler = $module_handler; $this->moduleHandler = $module_handler;
} }
...@@ -72,10 +58,7 @@ class ArbitraryUrlGenerator extends UrlGeneratorBase { ...@@ -72,10 +58,7 @@ class ArbitraryUrlGenerator extends UrlGeneratorBase {
$plugin_id, $plugin_id,
$plugin_definition, $plugin_definition,
$container->get('simple_sitemap.generator'), $container->get('simple_sitemap.generator'),
$container->get('language_manager'),
$container->get('entity_type.manager'),
$container->get('simple_sitemap.logger'), $container->get('simple_sitemap.logger'),
$container->get('simple_sitemap.entity_helper'),
$container->get('module_handler') $container->get('module_handler')
); );
} }
......
...@@ -23,7 +23,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface; ...@@ -23,7 +23,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
* ) * )
* *
*/ */
class CustomUrlGenerator extends UrlGeneratorBase { class CustomUrlGenerator extends EntityUrlGeneratorBase {
const PATH_DOES_NOT_EXIST_MESSAGE = 'The custom path @path has been omitted from the XML sitemaps as it does not exist. You can review custom paths <a href="@custom_paths_url">here</a>.'; const PATH_DOES_NOT_EXIST_MESSAGE = 'The custom path @path has been omitted from the XML sitemaps as it does not exist. You can review custom paths <a href="@custom_paths_url">here</a>.';
...@@ -44,22 +44,20 @@ class CustomUrlGenerator extends UrlGeneratorBase { ...@@ -44,22 +44,20 @@ class CustomUrlGenerator extends UrlGeneratorBase {
* @param $plugin_id * @param $plugin_id
* @param $plugin_definition * @param $plugin_definition
* @param \Drupal\simple_sitemap\Simplesitemap $generator * @param \Drupal\simple_sitemap\Simplesitemap $generator
* @param \Drupal\simple_sitemap\Logger $logger
* @param \Drupal\Core\Language\LanguageManagerInterface $language_manager * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* @param \Drupal\simple_sitemap\Logger $logger
* @param \Drupal\simple_sitemap\EntityHelper $entityHelper * @param \Drupal\simple_sitemap\EntityHelper $entityHelper
* @param \Drupal\Core\Path\PathValidator $path_validator * @param \Drupal\Core\Path\PathValidator $path_validator
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
*/ */
public function __construct( public function __construct(
array $configuration, array $configuration,
$plugin_id, $plugin_id,
$plugin_definition, $plugin_definition,
Simplesitemap $generator, Simplesitemap $generator,
Logger $logger,
LanguageManagerInterface $language_manager, LanguageManagerInterface $language_manager,
EntityTypeManagerInterface $entity_type_manager, EntityTypeManagerInterface $entity_type_manager,
Logger $logger,
EntityHelper $entityHelper, EntityHelper $entityHelper,
PathValidator $path_validator) { PathValidator $path_validator) {
parent::__construct( parent::__construct(
...@@ -67,9 +65,9 @@ class CustomUrlGenerator extends UrlGeneratorBase { ...@@ -67,9 +65,9 @@ class CustomUrlGenerator extends UrlGeneratorBase {
$plugin_id, $plugin_id,
$plugin_definition, $plugin_definition,
$generator, $generator,
$logger,
$language_manager, $language_manager,
$entity_type_manager, $entity_type_manager,
$logger,
$entityHelper $entityHelper
); );
$this->pathValidator = $path_validator; $this->pathValidator = $path_validator;
...@@ -85,9 +83,9 @@ class CustomUrlGenerator extends UrlGeneratorBase { ...@@ -85,9 +83,9 @@ class CustomUrlGenerator extends UrlGeneratorBase {
$plugin_id, $plugin_id,
$plugin_definition, $plugin_definition,
$container->get('simple_sitemap.generator'), $container->get('simple_sitemap.generator'),
$container->get('simple_sitemap.logger'),
$container->get('language_manager'), $container->get('language_manager'),
$container->get('entity_type.manager'), $container->get('entity_type.manager'),
$container->get('simple_sitemap.logger'),
$container->get('simple_sitemap.entity_helper'), $container->get('simple_sitemap.entity_helper'),
$container->get('path.validator') $container->get('path.validator')
); );
......
...@@ -27,7 +27,7 @@ use Drupal\Core\Menu\MenuLinkBase; ...@@ -27,7 +27,7 @@ use Drupal\Core\Menu\MenuLinkBase;
* *
* @todo Find way of adding just a menu link item pointer to the queue instead of whole object. * @todo Find way of adding just a menu link item pointer to the queue instead of whole object.
*/ */
class EntityMenuLinkContentUrlGenerator extends UrlGeneratorBase { class EntityMenuLinkContentUrlGenerator extends EntityUrlGeneratorBase {
/** /**
* @var \Drupal\Core\Menu\MenuLinkTree * @var \Drupal\Core\Menu\MenuLinkTree
...@@ -40,9 +40,9 @@ class EntityMenuLinkContentUrlGenerator extends UrlGeneratorBase { ...@@ -40,9 +40,9 @@ class EntityMenuLinkContentUrlGenerator extends UrlGeneratorBase {
* @param $plugin_id * @param $plugin_id
* @param $plugin_definition * @param $plugin_definition
* @param \Drupal\simple_sitemap\Simplesitemap $generator * @param \Drupal\simple_sitemap\Simplesitemap $generator
* @param \Drupal\simple_sitemap\Logger $logger
* @param \Drupal\Core\Language\LanguageManagerInterface $language_manager * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* @param \Drupal\simple_sitemap\Logger $logger
* @param \Drupal\simple_sitemap\EntityHelper $entityHelper * @param \Drupal\simple_sitemap\EntityHelper $entityHelper
* @param \Drupal\Core\Menu\MenuLinkTree $menu_link_tree * @param \Drupal\Core\Menu\MenuLinkTree $menu_link_tree
*/ */
...@@ -51,9 +51,9 @@ class EntityMenuLinkContentUrlGenerator extends UrlGeneratorBase { ...@@ -51,9 +51,9 @@ class EntityMenuLinkContentUrlGenerator extends UrlGeneratorBase {
$plugin_id, $plugin_id,
$plugin_definition, $plugin_definition,
Simplesitemap $generator, Simplesitemap $generator,
Logger $logger,
LanguageManagerInterface $language_manager, LanguageManagerInterface $language_manager,
EntityTypeManagerInterface $entity_type_manager, EntityTypeManagerInterface $entity_type_manager,
Logger $logger,
EntityHelper $entityHelper, EntityHelper $entityHelper,
MenuLinkTree $menu_link_tree MenuLinkTree $menu_link_tree
) { ) {
...@@ -62,9 +62,9 @@ class EntityMenuLinkContentUrlGenerator extends UrlGeneratorBase { ...@@ -62,9 +62,9 @@ class EntityMenuLinkContentUrlGenerator extends UrlGeneratorBase {
$plugin_id, $plugin_id,
$plugin_definition, $plugin_definition,
$generator, $generator,
$logger,
$language_manager, $language_manager,
$entity_type_manager, $entity_type_manager,
$logger,
$entityHelper $entityHelper
); );
$this->menuLinkTree = $menu_link_tree; $this->menuLinkTree = $menu_link_tree;
...@@ -80,9 +80,9 @@ class EntityMenuLinkContentUrlGenerator extends UrlGeneratorBase { ...@@ -80,9 +80,9 @@ class EntityMenuLinkContentUrlGenerator extends UrlGeneratorBase {
$plugin_id, $plugin_id,
$plugin_definition, $plugin_definition,
$container->get('simple_sitemap.generator'), $container->get('simple_sitemap.generator'),
$container->get('simple_sitemap.logger'),
$container->get('language_manager'), $container->get('language_manager'),
$container->get('entity_type.manager'), $container->get('entity_type.manager'),
$container->get('simple_sitemap.logger'),
$container->get('simple_sitemap.entity_helper'), $container->get('simple_sitemap.entity_helper'),
$container->get('menu.link_tree') $container->get('menu.link_tree')
); );
......
...@@ -19,7 +19,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface; ...@@ -19,7 +19,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
* description = @Translation("Generates URLs for entity bundles and bundle overrides."), * description = @Translation("Generates URLs for entity bundles and bundle overrides."),
* ) * )
*/ */
class EntityUrlGenerator extends UrlGeneratorBase { class EntityUrlGenerator extends EntityUrlGeneratorBase {
/** /**
* @var \Drupal\simple_sitemap\Plugin\simple_sitemap\UrlGenerator\UrlGeneratorManager * @var \Drupal\simple_sitemap\Plugin\simple_sitemap\UrlGenerator\UrlGeneratorManager
...@@ -32,9 +32,9 @@ class EntityUrlGenerator extends UrlGeneratorBase { ...@@ -32,9 +32,9 @@ class EntityUrlGenerator extends UrlGeneratorBase {
* @param $plugin_id * @param $plugin_id
* @param $plugin_definition * @param $plugin_definition
* @param \Drupal\simple_sitemap\Simplesitemap $generator * @param \Drupal\simple_sitemap\Simplesitemap $generator
* @param \Drupal\simple_sitemap\Logger $logger
* @param \Drupal\Core\Language\LanguageManagerInterface $language_manager * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* @param \Drupal\simple_sitemap\Logger $logger
* @param \Drupal\simple_sitemap\EntityHelper $entityHelper * @param \Drupal\simple_sitemap\EntityHelper $entityHelper
* @param \Drupal\simple_sitemap\Plugin\simple_sitemap\UrlGenerator\UrlGeneratorManager $url_generator_manager * @param \Drupal\simple_sitemap\Plugin\simple_sitemap\UrlGenerator\UrlGeneratorManager $url_generator_manager
*/ */
...@@ -43,9 +43,9 @@ class EntityUrlGenerator extends UrlGeneratorBase { ...@@ -43,9 +43,9 @@ class EntityUrlGenerator extends UrlGeneratorBase {
$plugin_id, $plugin_id,
$plugin_definition, $plugin_definition,
Simplesitemap $generator, Simplesitemap $generator,
Logger $logger,
LanguageManagerInterface $language_manager, LanguageManagerInterface $language_manager,
EntityTypeManagerInterface $entity_type_manager, EntityTypeManagerInterface $entity_type_manager,
Logger $logger,
EntityHelper $entityHelper, EntityHelper $entityHelper,
UrlGeneratorManager $url_generator_manager UrlGeneratorManager $url_generator_manager
) { ) {
...@@ -54,9 +54,9 @@ class EntityUrlGenerator extends UrlGeneratorBase { ...@@ -54,9 +54,9 @@ class EntityUrlGenerator extends UrlGeneratorBase {
$plugin_id, $plugin_id,
$plugin_definition, $plugin_definition,
$generator, $generator,
$logger,
$language_manager, $language_manager,
$entity_type_manager, $entity_type_manager,
$logger,
$entityHelper $entityHelper
); );
$this->urlGeneratorManager = $url_generator_manager; $this->urlGeneratorManager = $url_generator_manager;
...@@ -72,9 +72,9 @@ class EntityUrlGenerator extends UrlGeneratorBase { ...@@ -72,9 +72,9 @@ class EntityUrlGenerator extends UrlGeneratorBase {
$plugin_id, $plugin_id,
$plugin_definition, $plugin_definition,
$container->get('simple_sitemap.generator'), $container->get('simple_sitemap.generator'),
$container->get('simple_sitemap.logger'),
$container->get('language_manager'), $container->get('language_manager'),
$container->get('entity_type.manager'), $container->get('entity_type.manager'),
$container->get('simple_sitemap.logger'),
$container->get('simple_sitemap.entity_helper'), $container->get('simple_sitemap.entity_helper'),
$container->get('plugin.manager.simple_sitemap.url_generator') $container->get('plugin.manager.simple_sitemap.url_generator')
); );
...@@ -91,9 +91,8 @@ class EntityUrlGenerator extends UrlGeneratorBase { ...@@ -91,9 +91,8 @@ class EntityUrlGenerator extends UrlGeneratorBase {
if (isset($sitemap_entity_types[$entity_type_name])) { if (isset($sitemap_entity_types[$entity_type_name])) {
// Skip this entity type if another plugin is written to override its generation. // Skip this entity type if another plugin is written to override its generation.
// todo needs to be adjusted for variants
foreach ($this->urlGeneratorManager->getDefinitions() as $plugin) { foreach ($this->urlGeneratorManager->getDefinitions() as $plugin) {
if (!empty($plugin['settings']['overrides_entity_type']) if (isset($plugin['settings']['overrides_entity_type'])
&& $plugin['settings']['overrides_entity_type'] === $entity_type_name) { && $plugin['settings']['overrides_entity_type'] === $entity_type_name) {
continue 2; continue 2;
} }
......
<?php
namespace Drupal\simple_sitemap\Plugin\simple_sitemap\UrlGenerator;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Entity\ContentEntityBase;
use Drupal\Core\Url;
use Drupal\simple_sitemap\EntityHelper;
use Drupal\simple_sitemap\Logger;
use Drupal\simple_sitemap\Simplesitemap;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Language\Language;
use Drupal\Core\Session\AnonymousUserSession;
/**
* Class EntityUrlGeneratorBase
* @package Drupal\simple_sitemap\Plugin\simple_sitemap\UrlGenerator
*/
abstract class EntityUrlGeneratorBase extends UrlGeneratorBase {
/**
* @var \Drupal\Core\Language\LanguageInterface[]
*/
protected $languages;
/**
* @var string
*/
protected $defaultLanguageId;
/**
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* @var \Drupal\Core\Entity\EntityInterface|null
*/
protected $anonUser;
/**
* @var \Drupal\simple_sitemap\EntityHelper
*/
protected $entityHelper;
/**
* UrlGeneratorBase constructor.
* @param array $configuration
* @param $plugin_id
* @param $plugin_definition
* @param \Drupal\simple_sitemap\Simplesitemap $generator
* @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* @param \Drupal\simple_sitemap\Logger $logger
* @param \Drupal\simple_sitemap\EntityHelper $entityHelper
*/
public function __construct(
array $configuration,
$plugin_id,
$plugin_definition,
Simplesitemap $generator,
Logger $logger,
LanguageManagerInterface $language_manager,
EntityTypeManagerInterface $entity_type_manager,
EntityHelper $entityHelper
) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $generator, $logger);
$this->languages = $language_manager->getLanguages();
$this->defaultLanguageId = $language_manager->getDefaultLanguage()->getId();
$this->entityTypeManager = $entity_type_manager;
$this->anonUser = new AnonymousUserSession();
$this->entityHelper = $entityHelper;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$container->get('simple_sitemap.generator'),
$container->get('simple_sitemap.logger'),
$container->get('language_manager'),
$container->get('entity_type.manager'),
$container->get('simple_sitemap.entity_helper')
);
}
/**
* @param array $path_data
* @param \Drupal\Core\Url $url_object
* @return array
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
*/
protected function getUrlVariants(array $path_data, Url $url_object) {
$url_variants = [];
if (!$url_object->isRouted()) {
// Not a routed URL, including only default variant.
$alternate_urls = $this->getAlternateUrlsForDefaultLanguage($url_object);
}
elseif ($this->settings['skip_untranslated']
&& ($entity = $this->entityHelper->getEntityFromUrlObject($url_object)) instanceof ContentEntityBase) {
/** @var ContentEntityBase $entity */
$translation_languages = $entity->getTranslationLanguages();
if (isset($translation_languages[Language::LANGCODE_NOT_SPECIFIED])
|| isset($translation_languages[Language::LANGCODE_NOT_APPLICABLE])) {
// Content entity's language is unknown, including only default variant.
$alternate_urls = $this->getAlternateUrlsForDefaultLanguage($url_object);
}
else {
// Including only translated variants of content entity.
$alternate_urls = $this->getAlternateUrlsForTranslatedLanguages($entity, $url_object);
}
}
else {
// Not a content entity or including all untranslated variants.
$alternate_urls = $this->getAlternateUrlsForAllLanguages($url_object);
}
foreach ($alternate_urls as $langcode => $url) {
$url_variants[] = $path_data + [
'langcode' => $langcode,
'url' => $url,
'alternate_urls' => $alternate_urls
];
}
return $url_variants;
}
/**
* @param \Drupal\Core\Url $url_object
* @return array
*/
protected function getAlternateUrlsForDefaultLanguage(Url $url_object) {
$alternate_urls = [];
if ($url_object->access($this->anonUser)) {
$alternate_urls[$this->defaultLanguageId] = $this->replaceBaseUrlWithCustom($url_object
->setOption('language', $this->languages[$this->defaultLanguageId])->toString()
);
}
return $alternate_urls;
}
/**
* @param \Drupal\Core\Entity\ContentEntityBase $entity
* @param \Drupal\Core\Url $url_object
* @return array
*/
protected function getAlternateUrlsForTranslatedLanguages(ContentEntityBase $entity, Url $url_object) {
$alternate_urls = [];
/** @var Language $language */
foreach ($entity->getTranslationLanguages() as $language) {
if (!isset($this->settings['excluded_languages'][$language->getId()]) || $language->isDefault()) {
if ($entity->getTranslation($language->getId())->access('view', $this->anonUser)) {
$alternate_urls[$language->getId()] = $this->replaceBaseUrlWithCustom($url_object
->setOption('language', $language)->toString()
);
}
}
}
return $alternate_urls;
}
/**
* @param \Drupal\Core\Url $url_object
* @return array
*/
protected function getAlternateUrlsForAllLanguages(Url $url_object) {
$alternate_urls = [];
if ($url_object->access($this->anonUser)) {
foreach ($this->languages as $language) {
if (!isset($this->settings['excluded_languages'][$language->getId()]) || $language->isDefault()) {
$alternate_urls[$language->getId()] = $this->replaceBaseUrlWithCustom($url_object
->setOption('language', $language)->toString()
);
}
}
}
return $alternate_urls;
}
/**
* @param mixed $data_set
* @return array
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
*/
public function generate($data_set) {
$path_data = $this->processDataSet($data_set);
if (isset($path_data['url']) && $path_data['url'] instanceof Url) {
$url_object = $path_data['url'];
unset($path_data['url']);
return $this->getUrlVariants($path_data, $url_object);
}
else {
return FALSE !== $path_data ? [$path_data] : [];
}
}
/**
* @param string $entity_type_name
* @param string $entity_id
* @return array
*/
protected function getImages($entity_type_name, $entity_id) {
$images = [];
foreach ($this->entityHelper->getEntityImageUrls($entity_type_name, $entity_id) as $url) {
$images[]['path'] = $this->replaceBaseUrlWithCustom($url);
}
return $images;
}
}
...@@ -4,15 +4,8 @@ namespace Drupal\simple_sitemap\Plugin\simple_sitemap\UrlGenerator; ...@@ -4,15 +4,8 @@ namespace Drupal\simple_sitemap\Plugin\simple_sitemap\UrlGenerator;
use Drupal\simple_sitemap\Plugin\simple_sitemap\SimplesitemapPluginBase; use Drupal\simple_sitemap\Plugin\simple_sitemap\SimplesitemapPluginBase;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Entity\ContentEntityBase;
use Drupal\Core\Url;
use Drupal\simple_sitemap\EntityHelper;
use Drupal\simple_sitemap\Logger; use Drupal\simple_sitemap\Logger;
use Drupal\simple_sitemap\Simplesitemap; use Drupal\simple_sitemap\Simplesitemap;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Language\Language;
use Drupal\Core\Session\AnonymousUserSession;
/** /**
* Class UrlGeneratorBase * Class UrlGeneratorBase
...@@ -25,41 +18,16 @@ abstract class UrlGeneratorBase extends SimplesitemapPluginBase implements UrlGe ...@@ -25,41 +18,16 @@ abstract class UrlGeneratorBase extends SimplesitemapPluginBase implements UrlGe
*/ */
protected $generator; protected $generator;
/**
* @var \Drupal\Core\Language\LanguageInterface[]
*/
protected $languages;
/**
* @var string
*/
protected $defaultLanguageId;
/**
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/** /**
* @var \Drupal\simple_sitemap\Logger * @var \Drupal\simple_sitemap\Logger
*/ */
protected $logger; protected $logger;
/**
* @var \Drupal\Core\Entity\EntityInterface|null
*/
protected $anonUser;
/** /**
* @var array * @var array
*/ */
protected $settings; protected $settings;
/**
* @var \Drupal\simple_sitemap\EntityHelper
*/
protected $entityHelper;
/** /**
* @var string