Category Archives: Article

Comparatif Drupal 7 et 8 : page hello world

Voici les différences entre un module “hello world” le plus simple possible, entre Drupal 7 (code source) et Drupal 8 (code source).

Drupal 7 Drupal 8
hello.info hello.info.yml
name = Hello world
description = Minimanlist Hello World in Drupal 7
package = helloworld
core = 7.x
files[] = hello.module
name: Hello World module
type: module
description: An Hello World module showing D8 capabilites
package: Example modules
core: 8.x
hello.module hello.module
<?php

function hello_menu() {

  $items = array(
      'hello_world' => array(
        'title' => 'Hello world',
        'page callback' => '_page_hello_world',
        'access callback' => TRUE,
      ),
    );

  return $items;
}

function _page_hello_world() {
  return array(    '#markup' => '<p>Hello world page text (from module) !</p>' );
}
<?php
function hello_menu() {
  $items['hello'] = array(
    'title' => 'Hello Page',
    'route_name' => 'hello.world',
  );
  return $items;
}
 hello.routing.yml
# hello.routing.yml
hello.world:
  path: 'helloworld'
  defaults:
    _content: '\Drupal\hello\HelloRouteController::index'
  requirements:
    _permission: 'access content'
 /lib/Drupal/hello/HelloRouteController.php
<?php

namespace Drupal\hello;

class HelloRouteController {

  public function index() {
    return array('#markup' => 'Hello workd page text (from controller) !');
  }

}

Comme on peut le voir, le .info est convertit en fichier YAML .info.yml.…

Read more

Drupal 8 API Mindmap

Carte heuristique des concepts importants et changement d’API dans Drupal 8.

Get the Flash Player to see this player.

Read more