menu.php 1.28 KB
Newer Older
1 2 3 4 5 6
<?php
/**
 * @file
 * Contains \Drupal\simplesitemap\LinkGenerators\EntityTypeLinkGenerators\menu.
 *
 * Plugin for menu entity link generation.
7
 * See \Drupal\simplesitemap\LinkGenerators\CustomLinkGenerator\node_type for more
8 9 10 11 12 13 14 15 16 17 18 19 20
 * documentation.
 */

namespace Drupal\simplesitemap\LinkGenerators\EntityTypeLinkGenerators;

use Drupal\simplesitemap\LinkGenerators\EntityLinkGenerator;
use Drupal\Core\Url;

/**
 * menu class.
 */
class menu extends EntityLinkGenerator {

21 22 23
  /**
   * {@inheritdoc}
   */
24
  function get_entity_bundle_links($bundle, $languages) {
25 26 27 28 29 30 31
    $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;
32
      $options = !empty($route_parameters = unserialize($entity->route_parameters)) ? array(key($route_parameters) => $route_parameters[key($route_parameters)]) : array();
33 34 35 36 37 38
      foreach($languages as $language) {
        $urls[$id][$language->getId()] = Url::fromRoute($entity->route_name, $options, array(
          'language' => $language,
          'absolute' => TRUE
        ))->toString();
      }
39 40 41 42
    }
    return $urls;
  }
}