protected function DefaultSitemapGenerator::addUrl in Simple XML sitemap 8.3
Same name and namespace in other branches
- 4.x src/Plugin/simple_sitemap/SitemapGenerator/DefaultSitemapGenerator.php \Drupal\simple_sitemap\Plugin\simple_sitemap\SitemapGenerator\DefaultSitemapGenerator::addUrl()
Adds a URL element to the sitemap.
Parameters
array $url_data: The array of properties for this URL.
1 call to DefaultSitemapGenerator::addUrl()
- DefaultSitemapGenerator::addLinks in src/
Plugin/ simple_sitemap/ SitemapGenerator/ DefaultSitemapGenerator.php - Adds URL elements to the sitemap.
File
- src/
Plugin/ simple_sitemap/ SitemapGenerator/ DefaultSitemapGenerator.php, line 97
Class
- DefaultSitemapGenerator
- Class DefaultSitemapGenerator @package Drupal\simple_sitemap\Plugin\simple_sitemap\SitemapGenerator
Namespace
Drupal\simple_sitemap\Plugin\simple_sitemap\SitemapGeneratorCode
protected function addUrl(array $url_data) {
$this->writer
->writeElement('loc', $url_data['url']);
// If more than one language is enabled, add all translation variant URLs
// as alternate links to this link turning the sitemap into a hreflang
// sitemap.
if (isset($url_data['alternate_urls']) && $this
->isHreflangSitemap()) {
$this
->addAlternateUrls($url_data['alternate_urls']);
}
// Add lastmod if any.
if (isset($url_data['lastmod'])) {
$this->writer
->writeElement('lastmod', $url_data['lastmod']);
}
// Add changefreq if any.
if (isset($url_data['changefreq'])) {
$this->writer
->writeElement('changefreq', $url_data['changefreq']);
}
// Add priority if any.
if (isset($url_data['priority'])) {
$this->writer
->writeElement('priority', $url_data['priority']);
}
// Add images if any.
if (!empty($url_data['images'])) {
foreach ($url_data['images'] as $image) {
$this->writer
->startElement('image:image');
$this->writer
->writeElement('image:loc', $image['path']);
if (strlen($image['title']) > 0) {
$this->writer
->writeElement('image:title', $image['title']);
}
if (strlen($image['alt']) > 0) {
$this->writer
->writeElement('image:caption', $image['alt']);
}
$this->writer
->endElement();
}
}
}