Commit e63c8e6c authored by Pawel G's avatar Pawel G

Clean up

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