public function MenuHierarchy::query

Called to add the sort to a query.

Overrides SortPluginBase::query

File

drupal/core/modules/views/lib/Drupal/views/Plugin/views/sort/MenuHierarchy.php, line 44
Definition of Drupal\views\Plugin\views\sort\MenuHierarchy.

Class

MenuHierarchy
Sort in menu hierarchy order.

Namespace

Drupal\views\Plugin\views\sort

Code

public function query() {
  $this
    ->ensureMyTable();
  $max_depth = isset($this->definition['max depth']) ? $this->definition['max depth'] : MENU_MAX_DEPTH;
  for ($i = 1; $i <= $max_depth; ++$i) {
    if ($this->options['sort_within_level']) {
      $definition = array(
        'table' => 'menu_links',
        'field' => 'mlid',
        'left_table' => $this->tableAlias,
        'left_field' => $this->field . $i,
      );
      $join = drupal_container()
        ->get('plugin.manager.views.join')
        ->createInstance('standard', $definition);
      $menu_links = $this->query
        ->add_table('menu_links', NULL, $join);
      $this->query
        ->add_orderby($menu_links, 'weight', $this->options['order']);
      $this->query
        ->add_orderby($menu_links, 'link_title', $this->options['order']);
    }

    // We need this even when also sorting by weight and title, to make sure
    // that children of two parents with the same weight and title are
    // correctly separated.
    $this->query
      ->add_orderby($this->tableAlias, $this->field . $i, $this->options['order']);
  }
}