Commit d84dd29c authored by alexpott's avatar alexpott

Issue #1987688 by cbiggins, jibran: Convert design_test_category_page() to a new style controller.

parent b96a2640
......@@ -68,21 +68,19 @@ function design_test_menu() {
$items['design_test'] = array(
'title' => 'Design test',
'page callback' => 'design_test_category_page',
'page arguments' => array(1),
'access callback' => TRUE,
'route_name' => 'design_test',
);
$items['design_test/list'] = array(
'title' => 'List',
'type' => MENU_DEFAULT_LOCAL_TASK,
);
// Lastly, add the category containers.
foreach ($categories as $category) {
$items["design_test/{$category}"] = array(
'title' => drupal_ucfirst($category),
'page callback' => 'design_test_category_page',
'page arguments' => array(1),
'access callback' => TRUE,
'route_name' => 'design_test',
'type' => MENU_LOCAL_TASK | MENU_VISIBLE_IN_TREE,
);
}
......@@ -133,36 +131,3 @@ function design_test_menu_local_tasks_alter(&$data, $router_item, $root_path) {
function design_test_menu_theme_callback() {
return drupal_container()->get('request')->query->get('theme');
}
/**
* Menu page callback for a category listing page.
*
* This is a specialized version of system_admin_menu_block_page(), which
* retrieves all direct child menu links of the current page, regardless of
* their type, skips default local tasks, and outputs them as a simple menu
* tree as the main page content.
*
* @param string $category
* The design test category being currently accessed. Maps to the subdirectory
* names of this module.
*
* @return array
* A render array containing a menu link tree.
*/
function design_test_category_page($category) {
$link = menu_link_get_preferred();
$tree = menu_build_tree($link['menu_name'], array(
'expanded' => array($link['mlid']),
'min_depth' => $link['depth'] + 1,
'max_depth' => $link['depth'] + 2,
));
// Local tasks are hidden = -1, so normally not rendered in menu trees.
foreach ($tree as &$data) {
// Exclude default local tasks.
if (!($data['link']['type'] & MENU_LINKS_TO_PARENT)) {
$data['link']['hidden'] = 0;
}
}
$build = menu_tree_output($tree);
return $build;
}
design_test:
pattern: '/design_test/{category}'
defaults:
_content: '\Drupal\design_test\Controller\DesignTestController::categoryPage'
category: 'FALSE'
requirements:
_access: 'TRUE'
<?php
/**
* @file
* Contains \Drupal\design_test\Controller\DesignTestController.
*/
namespace Drupal\design_test\Controller;
use Drupal\Core\ControllerInterface;
/**
* Controller routines for design_test routes.
*/
class DesignTestController implements ControllerInterface {
/**
* {@inheritdoc}
*/
public static function create() {
return new static();
}
/**
* Constructs a DesignTestController object.
*/
public function __construct() {
}
/**
* Menu for a category listing page.
*
* This is a specialized version of system_admin_menu_block_page(), which
* retrieves all direct child menu links of the current page, regardless of
* their type, skips default local tasks, and outputs them as a simple menu
* tree as the main page content.
*
* @param string $category
* The design test category being currently accessed.
* Maps to the subdirectory names of this module.
*
* @return array
* A render array containing a menu link tree.
*/
public function categoryPage($category) {
$link = menu_link_get_preferred();
$tree = menu_build_tree($link['menu_name'], array(
'expanded' => array($link['mlid']),
'min_depth' => $link['depth'] + 1,
'max_depth' => $link['depth'] + 2,
));
// Local tasks are hidden = -1, so normally not rendered in menu trees.
foreach ($tree as &$data) {
// Exclude default local tasks.
if (!($data['link']['type'] & MENU_LINKS_TO_PARENT)) {
$data['link']['hidden'] = 0;
}
}
return menu_tree_output($tree);
}
}
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