Commit e63c8e6c authored by gbyte.co's avatar gbyte.co

Clean up

parent a26700d7
......@@ -50,7 +50,9 @@ function hook_simple_sitemap_arbitrary_links_alter(&$arbitrary_links) {
'priority' => '0.5',
'lastmod' => '2012-10-12T17:40:30+02:00',
'changefreq' => 'weekly',
'images' => ['http://path-to-image.png']
'images' => [
['path' =>'http://path-to-image.png']
]
];
}
......
......@@ -12,12 +12,14 @@ class ArbitraryUrlGenerator extends UrlGeneratorBase implements UrlGeneratorInte
* Batch function that adds arbitrary URLs to the sitemap.
*
* @param mixed $arbitrary_paths
*
* @see \hook_simple_sitemap_arbitrary_links_alter()
*/
public function generate($arbitrary_paths) {
foreach ($this->getBatchIterationElements($arbitrary_paths) as $i => $path_data) {
$this->setCurrentId($i);
$this->context['results']['generate'][] = $path_data;
$this->addUrl($path_data);
}
$this->processSegment();
}
......
......@@ -54,7 +54,7 @@ class CustomUrlGenerator extends UrlGeneratorBase implements UrlGeneratorInterfa
'id' => $entity->id()
];
}
$this->addUrlVariants($url_object, $path_data, $entity);
$this->addUrl($path_data, $url_object);
}
$this->processSegment();
}
......
......@@ -64,15 +64,28 @@ class EntityUrlGenerator extends UrlGeneratorBase implements UrlGeneratorInterfa
'priority' => isset($entity_settings['priority']) ? $entity_settings['priority'] : NULL,
'changefreq' => !empty($entity_settings['changefreq']) ? $entity_settings['changefreq'] : NULL,
'images' => $entity_settings['include_images']
? $this->entityHelper->getEntityImageUris($entity_info['entity_type_name'], $entity_id)
? $this->getImages($entity_info['entity_type_name'], $entity_id)
: []
];
$this->addUrlVariants($url_object, $path_data, $entity);
$this->addUrl($path_data, $url_object);
}
$this->processSegment();
}
/**
* @param $entity_type_name
* @param $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'] = $Url;
}
return $images;
}
/**
* @param array $entity_info
* @return \Drupal\Core\Entity\EntityInterface[]
......
......@@ -158,14 +158,26 @@ class UrlGeneratorBase {
return FALSE;
}
/**
* @param array $path_data
* @param \Drupal\Core\Url|NULL $url_object
*/
protected function addUrl(array $path_data, Url $url_object = NULL) {
if ($url_object !== NULL) {
$this->addUrlVariants($path_data, $url_object);
}
else {
$this->context['results']['generate'][] = $path_data;
}
}
/**
* @param Url $url_object
* @param array $path_data
* @param Entity $entity
*/
protected function addUrlVariants(Url $url_object, array $path_data, Entity $entity = null) {
protected function addUrlVariants(array $path_data, Url $url_object) {
$alternate_urls = [];
$entity = $this->entityHelper->getEntityFromUrlObject($url_object);
$translation_languages = $entity instanceof ContentEntityBase && $this->batchInfo['skip_untranslated']
? $entity->getTranslationLanguages()
: $this->languages;
......@@ -199,7 +211,8 @@ class UrlGeneratorBase {
}
foreach ($alternate_urls as $langcode => $url) {
$this->context['results']['generate'][] = $path_data + ['langcode' => $langcode, 'url' => $url, 'alternate_urls' => $alternate_urls];
$this->context['results']['generate'][] = $path_data + [
'langcode' => $langcode, 'url' => $url, 'alternate_urls' => $alternate_urls];
}
}
......
......@@ -118,7 +118,7 @@ class EntityHelper {
* @param $entity_id
* @return array
*/
public function getEntityImageUris($entity_type_name, $entity_id) {
public function getEntityImageUrls($entity_type_name, $entity_id) {
$query = $this->db->select('file_managed', 'fm');
$query->fields('fm', ['uri']);
$query->join('file_usage', 'fu', 'fu.fid = fm.fid');
......
......@@ -37,7 +37,6 @@ class SitemapGenerator {
*/
protected $db;
/**
* @var \Drupal\Core\Language\LanguageManagerInterface
*/
......@@ -63,12 +62,18 @@ class SitemapGenerator {
*/
protected $generator;
/**
* @var array
*/
protected static $attributes = [
'xmlns' => self::XMLNS,
'xmlns:xhtml' => self::XMLNS_XHTML,
'xmlns:image' => self::XMLNS_IMAGE,
];
/**
* @var array
*/
protected static $indexAttributes = [
'xmlns' => self::XMLNS,
];
......@@ -336,9 +341,9 @@ class SitemapGenerator {
// Add images if any.
if (!empty($link['images'])) {
foreach ($link['images'] as $image_url) {
foreach ($link['images'] as $image) {
$writer->startElement('image:image');
$writer->writeElement('image:loc', $image_url);
$writer->writeElement('image:loc', $image['path']);
$writer->endElement();
}
}
......
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