Menu.php 1.27 KB
Newer Older
1 2 3
<?php
/**
 * @file
4
 * Contains \Drupal\simplesitemap\LinkGenerator\Menu.
5 6 7 8
 *
 * Plugin for menu entity link generation.
 */

9
namespace Drupal\simplesitemap\Plugin\LinkGenerator;
10

11 12
use Drupal\simplesitemap\Annotation\LinkGenerator;
use Drupal\simplesitemap\LinkGeneratorBase;
13 14

/**
15 16 17 18 19
 * Menu class.
 *
 * @LinkGenerator(
 *   id = "menu"
 * )
20
 */
21
class Menu extends LinkGeneratorBase {
22

23 24 25
  /**
   * {@inheritdoc}
   */
26
  function get_paths($bundle) {
27
    $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))
28 29
      ->fetchAllAssoc('mlid');

30
    $paths = array();
31 32 33
    foreach ($routes as $id => $entity) {
      if (empty($entity->route_name))
        continue;
34

35 36 37
      //todo: There may be a better way to do this.
      $options = !empty($options = unserialize($entity->options)) ? $options : array();
      $route_parameters = !empty($route_parameters = unserialize($entity->route_parameters))
38
        ? array(key($route_parameters) => $route_parameters[key($route_parameters)]) : array();
39 40 41

      $paths[$id]['path_data'] = $this->get_multilang_urls_from_route($entity->route_name, $route_parameters, $options);
      //todo: Implement lastmod for menu items.
42
    }
43
    return $paths;
44 45
  }
}