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

Plugins can now add link options (url parameters and anchors). Sitemap now...

Plugins can now add link options (url parameters and anchors). Sitemap now accepts url parameters and anchors.
parent c9b4e5d4
......@@ -31,13 +31,13 @@ abstract class LinkGeneratorBase extends PluginBase implements LinkGeneratorInte
}
foreach($paths as $id => $path) {
// Some error catching.
if (!isset($path['path']) || !is_string($path['path'])) { // Error catching; careful, path can be empty.
$this->register_error(self::PLUGIN_ERROR_MESSAGE);
return $this->entity_paths;
}
$this->entity_paths[$i]['path'] = $path['path'];
$this->entity_paths[$i]['options'] = !empty($path['options']) ? $path['options'] : array();
$this->entity_paths[$i]['priority'] = !empty($path['priority']) ? $path['priority'] : $bundle_settings['priority'];
$this->entity_paths[$i]['lastmod'] = isset($path['lastmod']) && is_numeric($path['lastmod']) ? date_iso8601($path['lastmod']) : NULL;
$i++;
......@@ -60,10 +60,14 @@ abstract class LinkGeneratorBase extends PluginBase implements LinkGeneratorInte
*
* @return array $paths
* A numeric array of Drupal internal path data sets containing the path and
* lastmod info:
* optionally lastmod and link options:
* array(
* path => 'drupal/internal/path/to/content', // required
* lastmod => '1234567890' // content changed unix date, optional
* 'path' => 'drupal/internal/path/to/content', // required
* 'options' => array( // optional
* 'query' => array('page' => '1'),
* 'fragment' => 'my-anchor-id',
* ),
* 'lastmod' => '1234567890' // optional: content changed unix date
* )
*
* @abstract
......
......@@ -25,7 +25,7 @@ class Menu extends LinkGeneratorBase {
* {@inheritdoc}
*/
function get_entity_bundle_paths($bundle) {
$routes = db_query("SELECT mlid, route_name, route_parameters FROM {menu_tree} WHERE menu_name = :menu_name and enabled = 1", array(':menu_name' => $bundle))
$routes = db_query("SELECT mlid, route_name, route_parameters, options FROM {menu_tree} WHERE menu_name = :menu_name and enabled = 1", array(':menu_name' => $bundle))
->fetchAllAssoc('mlid');
$paths = array();
......@@ -33,11 +33,13 @@ class Menu extends LinkGeneratorBase {
if (empty($entity->route_name))
continue;
$paths[$id]['options'] = !empty($options = unserialize($entity->options)) ? $options : array();
//todo: Use Url::getRouteParameters()?
$options = !empty($route_parameters = unserialize($entity->route_parameters))
$route_parameters = !empty($route_parameters = unserialize($entity->route_parameters))
? array(key($route_parameters) => $route_parameters[key($route_parameters)]) : array();
$paths[$id]['path'] = Url::fromRoute($entity->route_name, $options, array())->getInternalPath();
$paths[$id]['path'] = Url::fromRoute($entity->route_name, $route_parameters, $options)->getInternalPath();
//todo: Implement lastmod for menu items.
}
return $paths;
......
......@@ -103,7 +103,9 @@ class SitemapGenerator {
foreach($this->languages as $language) {
$this->links[$i]['url'][$language->getId()] = Url::fromUserInput('/' . $link['path'], array(
'language' => $language,
'absolute' => TRUE
'absolute' => TRUE,
'query' => !empty($link['options']['query']) ? $link['options']['query'] : array(),
'fragment' => !empty($link['options']['fragment']) ? $link['options']['fragment'] : '',
))->toString();
}
}
......
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