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

Adding lastmod info to node and taxonomy sitemap links.

parent eb7ec50d
......@@ -24,11 +24,20 @@ abstract class EntityLinkGenerator {
continue;
}
$links = $this->get_entity_bundle_links($entity_type, $bundle, $language);
foreach ($links as &$link) {
$link = SitemapGenerator::add_xml_link_markup($link, $bundle_settings['priority']);
$lastmod = NULL;
foreach ($links as $id => &$link) {
switch ($entity_type) {
case 'node':
$lastmod = db_query("SELECT changed FROM {node_field_data} WHERE nid = :nid LIMIT 1", array(':nid' => $id))->fetchCol();
break;
case 'taxonomy_term':
$lastmod = db_query("SELECT changed FROM {taxonomy_term_field_data} WHERE tid = :tid LIMIT 1", array(':tid' => $id))->fetchCol();
break;
case 'menu':
//todo: to be implemented
}
$this->entity_links[] = SitemapGenerator::add_xml_link_markup($link, $bundle_settings['priority'], isset($lastmod[0]) ? date_iso8601($lastmod[0]) : NULL);
}
$this->entity_links = array_merge($this->entity_links, $links);
}
return $this->entity_links;
}
......
......@@ -26,19 +26,11 @@ class menu extends EntityLinkGenerator {
foreach ($routes as $id => $entity) {
if (empty($entity->route_name))
continue;
if (!empty($route_parameters = unserialize($entity->route_parameters))) {
$key = key($route_parameters);
$urls[] = Url::fromRoute($entity->route_name, array($key => $route_parameters[$key]), array(
'language' => $language,
'absolute' => TRUE
))->toString();
}
else {
$urls[] = Url::fromRoute($entity->route_name, array(), array(
'language' => $language,
'absolute' => TRUE
))->toString();
}
$options = !empty($route_parameters = unserialize($entity->route_parameters)) ? array(key($route_parameters) => $route_parameters[key($route_parameters)]) : array();
$urls[] = Url::fromRoute($entity->route_name, $options, array(
'language' => $language,
'absolute' => TRUE
))->toString();
}
return $urls;
}
......
......@@ -25,16 +25,13 @@ use Drupal\Core\Url;
class node extends EntityLinkGenerator {
function get_entity_bundle_links($entity_type, $bundle, $language) {
$ids = array();
$query = \Drupal::entityQuery($entity_type)
->condition('status', 1)
->condition('type', $bundle);
$ids += $query->execute();
$results = db_query("SELECT nid FROM {node_field_data} WHERE status = 1 AND type = :type", array(':type' => $bundle))
->fetchAllAssoc('nid');
$urls = array();
foreach ($ids as $id => $entity) {
$urls[] = Url::fromRoute("entity.$entity_type.canonical", array('node' => $id), array(
foreach ($results as $id => $changed) {
$urls[$id] = Url::fromRoute("entity.$entity_type.canonical", array('node' => $id), array(
'language' => $language,
'absolute' => TRUE
))->toString();
......
......@@ -20,14 +20,13 @@ class taxonomy_term extends EntityLinkGenerator {
function get_entity_bundle_links($entity_type, $bundle, $language) {
$ids = array();
$query = \Drupal::entityQuery($entity_type)
->condition('vid', $bundle);
$ids += $query->execute();
//todo: check what happens if none existent.
$results = db_query("SELECT tid FROM {taxonomy_term_field_data} WHERE vid = :vid", array(':vid' => $bundle))
->fetchAllAssoc('tid');
$urls = array();
foreach ($ids as $id => $entity) {
$urls[] = Url::fromRoute("entity.$entity_type.canonical", array('taxonomy_term' => $id), array(
foreach ($results as $id => $changed) {
$urls[$id] = Url::fromRoute("entity.$entity_type.canonical", array('taxonomy_term' => $id), array(
'language' => $language,
'absolute' => TRUE
))->toString();
......
......@@ -36,8 +36,11 @@ class SitemapGenerator {
return $options;
}
public static function add_xml_link_markup($url, $priority) {
return "<url><loc>" . $url . "</loc><priority>" . $priority . "</priority></url>";
public static function add_xml_link_markup($url, $priority = NULL, $lastmod = NULL) {
return "<url><loc>" . $url . "</loc>"
. (!is_null($priority) ? ("<priority>" . $priority . "</priority>") : '')
. (!is_null($lastmod) ? ("<lastmod>" . $lastmod . "</lastmod>") : '')
. "</url>";
}
public function set_entity_types($entity_types) {
......
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