Commit 2d1a35a0 authored by gbyte.co's avatar gbyte.co

Do not show lastmod for menu item URLs

parent 637c6709
......@@ -84,10 +84,14 @@ class EntityUrlGenerator extends UrlGeneratorBase {
$url_object->setOption('absolute', TRUE);
$lastmod = method_exists($entity, 'getChangedTime') ? date_iso8601($entity->getChangedTime()) : NULL;
// Menu fix.
$lastmod = $entity_type_name !== 'menu_link_content' ? $lastmod : NULL;
return [
'url' => $url_object,
'lastmod' => method_exists($entity, 'getChangedTime')
? date_iso8601($entity->getChangedTime()) : NULL,
'lastmod' => $lastmod,
'priority' => isset($entity_settings['priority']) ? $entity_settings['priority'] : NULL,
'changefreq' => !empty($entity_settings['changefreq']) ? $entity_settings['changefreq'] : NULL,
'images' => !empty($entity_settings['include_images'])
......
......@@ -3,8 +3,6 @@
namespace Drupal\simple_sitemap\Tests;
/**
* Class SimplesitemapTest
*
* Tests Simple XML sitemap functional integration.
*
* @package Drupal\simple_sitemap\Tests
......@@ -157,6 +155,36 @@ class SimplesitemapTest extends SimplesitemapTestBase {
$this->assertNoRaw('changefreq');
}
/**
* Test the lastmod parameter in different scenarios.
*/
public function testLastmod() {
// Entity links should have 'lastmod'.
$this->generator->setBundleSettings('node', 'page')
->removeCustomLinks()
->generateSitemap('nobatch');
$this->drupalGet('sitemap.xml');
$this->assertRaw('lastmod');
// Entity custom links should have 'lastmod'.
$this->generator->setBundleSettings('node', 'page', ['index' => FALSE])
->addCustomLink('/node/' . $this->node->id())
->generateSitemap('nobatch');
$this->drupalGet('sitemap.xml');
$this->assertRaw('lastmod');
// Non-entity custom links should not have 'lastmod'.
$this->generator->removeCustomLinks()
->addCustomLink('/')
->generateSitemap('nobatch');
$this->drupalGet('sitemap.xml');
$this->assertNoRaw('lastmod');
}
/**
* Tests the duplicate setting.
*
......@@ -256,16 +284,24 @@ class SimplesitemapTest extends SimplesitemapTestBase {
$this->assertText('never');
}
/**
* Test indexing an atomic entity (here: a user).
* Test indexing an atomic entity (here: a user)
* @todo Not working
*/
public function indexAtomicEntity() {
/* public function testAtomicEntityIndexation() {
$user = $this->createPrivilegedUser();
$this->generator->setBundleSettings('user');
$this->generator->setBundleSettings('user')
->generateSitemap('nobatch');
$this->drupalGet('sitemap.xml');
$this->assertNoText('user/' . $user->id());
user_role_grant_permissions(0, ['access user profiles']);
$this->generator->generateSitemap('nobatch');
$this->drupalGet('sitemap.xml');
$this->assertText('user/' . $user->id());
}
}*/
/**
* @todo Test indexing menu.
......
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