Drupal 8 Interconnections , drupal8 模块的demo
from:
http://josephbcasey.github.io/d8-interconnections-demo/
https://www.drupal.org/node/2464195
This shows the complete files needed for a 'hello' module, highlighting the interconnections between various pieces. The interconnections are color-coded, and can be enlarged for easier recognition by clicking on them.
Text with a border has added explanations that can be displayed and hidden by clicking.
The crude mock browser on the right shows the finished page.
This is a work in progress. Last modified November 17th, 2015. Corrections, comments and suggestions are welcome. Joe Casey
Mock Browser:
Hello Title
https://www.example.com/say_hello
Hello Title
Hello there!
File: modules/custom/hello/hello.routing.yml:
hello:
path: '/say_hello'
defaults:
_title: 'Hello Title'
_controller: '\Drupal\hello\HelloController::content'
requirements:
_permission: 'access content'
File: modules/custom/hello/src/HelloController.php:
<?php
/**
* @file
* Contains \Drupal\hello\HelloController.
*/
namespace Drupal\hello;
Required. Some variations are possible.
See Namespaces
and Getting Started - Background & Prerequisites (Drupal 8).
use Drupal\Core\Controller\ControllerBase;
"Utility base class for thin controllers."
See abstract class ControllerBase.
This is, in a sense, the connection to core Drupal and Symfony. There are many other ways to set this up.
class HelloController extends ControllerBase {
public function content() {
return array(
'#markup' => '' . t('Hello there!') . '',
);
}
}
File: modules/custom/hello/hello.module:
This file is required but can be empty.
See Naming and placing your Drupal 8 module.
<?php
/**
* @file
* Hello module.
*/
File: modules/custom/hello/hello.info.yml:
name: Hello
type: module
description: Hello demo module.
core: 8.x