Commit 6bb4ed6f authored by gbyte.co's avatar gbyte.co

Added menu support. Changed some variable names.

parent f0e94fc3
...@@ -77,8 +77,6 @@ function simplesitemap_entity_form_submit($form, &$form_state) { ...@@ -77,8 +77,6 @@ function simplesitemap_entity_form_submit($form, &$form_state) {
// Regenerate sitemaps for all languages and save them into strings for performance reason (pseudo caching). // Regenerate sitemaps for all languages and save them into strings for performance reason (pseudo caching).
$sitemap->generate_all_sitemaps(); $sitemap->generate_all_sitemaps();
drupal_set_message(t('XML sitemaps have been regenerated for all languages.'));
} }
} }
......
...@@ -92,15 +92,15 @@ class SimplesitemapCustomLinksForm extends ConfigFormBase { ...@@ -92,15 +92,15 @@ class SimplesitemapCustomLinksForm extends ConfigFormBase {
$sitemap = new Simplesitemap; $sitemap = new Simplesitemap;
$custom_links_string = str_replace("\r\n", "\n", $form_state->getValue('custom_links')); $custom_links_string = str_replace("\r\n", "\n", $form_state->getValue('custom_links'));
$custom_links = array_filter(explode("\n", $custom_links_string), 'trim'); $custom_links_string_lines = array_filter(explode("\n", $custom_links_string), 'trim');
$custom_link_config = array(); $custom_link_config = array();
foreach($custom_links as $link_setting) { foreach($custom_links_string_lines as $line) {
$settings = explode(' ', $link_setting, 2); $line_settings = explode(' ', $line, 2);
$custom_link_config[]['path'] = $settings[0]; $custom_link_config[]['path'] = $line_settings[0];
if (isset($settings[1])) { if (isset($line_settings[1])) {
end($custom_link_config); end($custom_link_config);
$key = key($custom_link_config); $key = key($custom_link_config);
$custom_link_config[$key]['priority'] = number_format((float)$settings[1], 1, '.', ''); $custom_link_config[$key]['priority'] = number_format((float)$line_settings[1], 1, '.', '');
} }
} }
$sitemap->save_custom_links($custom_link_config); $sitemap->save_custom_links($custom_link_config);
......
<?php
/**
* @file
* Contains \Drupal\simplesitemap\LinkGenerators\EntityTypeLinkGenerators\menu.
*
* Plugin for menu entity link generation.
* See \Drupal\simplesitemap\LinkGenerators\CustomLinkGenerator\node for more
* documentation.
*/
namespace Drupal\simplesitemap\LinkGenerators\EntityTypeLinkGenerators;
use Drupal\simplesitemap\LinkGenerators\EntityLinkGenerator;
use Drupal\Core\Url;
/**
* menu class.
*/
class menu extends EntityLinkGenerator {
function get_entity_bundle_links($entity_type, $bundle, $language) {
$routes = db_query("SELECT mlid, route_name, route_parameters FROM {menu_tree} WHERE menu_name = :menu_name and enabled = 1", array(':menu_name' => $bundle))
->fetchAllAssoc('mlid');
$urls = array();
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();
}
}
return $urls;
}
}
...@@ -32,6 +32,12 @@ class Simplesitemap { ...@@ -32,6 +32,12 @@ class Simplesitemap {
public static function get_entity_type_name($entity) { public static function get_entity_type_name($entity) {
if (method_exists($entity, 'getEntityType')) { if (method_exists($entity, 'getEntityType')) {
if (!$entity_type_name = $entity->getEntityType()->getBundleOf()) {
if (method_exists($entity, 'getEntityTypeId')) {
return $entity->getEntityTypeId();
}
}
return $entity->getEntityType()->getBundleOf(); return $entity->getEntityType()->getBundleOf();
} }
return FALSE; return FALSE;
...@@ -107,6 +113,7 @@ class Simplesitemap { ...@@ -107,6 +113,7 @@ class Simplesitemap {
$this->sitemap = $generator->generate_sitemap(); $this->sitemap = $generator->generate_sitemap();
$this->save_sitemap(); $this->save_sitemap();
} }
drupal_set_message(t('XML sitemaps have been regenerated for all languages.'));
} }
private function save_sitemap() { private function save_sitemap() {
......
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