Change record status: 
Project: 
Introduced in branch: 
8.x
Description: 

With the introduction of the Drupal 8 routing system, hook_menu() page callbacks throughout Drupal core have been replaced with new controller classes. (See also: ControllerBase class available for routing controllers to minimize boilerplate code.)

Drupal 7

hello.module

function hello_menu() {
  return array(
    'hello' => array(
      'title' => 'Hello world',
      'page callback' => 'hello_page',
      'access callback' => 'user_access', 
      'access arguments' => array('access content'),
    ), 
  ); 
} 

function hello_page() { 
  return array( 
    '#type' => 'markup', 
    '#markup' => t('Hello.'), 
  ); 
} 

Drupal 8

hello.routing.yml

hello: 
  path: '/hello' 
  defaults: 
    _controller: '\Drupal\hello\Controller\HelloController::content' 
    _title: 'Hello world'
  requirements: 
    _permission: 'access content' 

src/Controller/HelloController.php


namespace Drupal\hello\Controller;

class HelloController {
  public function content() {
    return array(
      '#type' => 'markup', 
      '#markup' => t('Hello.'), 
    ); 
  } 
} 
Impacts: 
Module developers
Updates Done (doc team, etc.)
Online documentation: 
Not done
Theming guide: 
Not done
Module developer documentation: 
Not done
Examples project: 
Not done
Coder Review: 
Not done
Coder Upgrade: 
Not done
Other: 
Other updates done

Comments

vlad13’s picture

In D6/7 there was a possibility to pass `page arguments` to `page callback`:

  $items['system/files/%'] = array(
    'access arguments' => array('access private download directory'),
    'page callback' => 'file_download',
    'page arguments' => array(2),
    'type' => MENU_CALLBACK,
  );

Is there smth similar in Drupal 8?