Reference:
Https://www.drupal.org/developing/modules/8
https://www.drupal.org/node/1915030
https://www.drupal.org/node/318
Drupal 8 RC was released. Because the D8 uses the Symfony2 kernel. Compared to previous versions, the module is very different in its notation.
New module
The following example writes a module that displays the "Hello World" page separately.
The first thing to do is to give the module a unique machine name
The machine name must meet:
1. Beginning of letter
2. Can only contain lowercase letters and underscores
3. Must be unique and cannot be the same name as other modules, themes and profiles (profile)
4. Cannot be SRC, lib, vendor, assets, CSS, files, images, JS, misc, templates, includes, fixtures, Drupal. These are reserved keywords.
Info.yml
Create a new "Hello_world" directory in the modules directory of the root directory.
Then create a new hello_world.info.yml, which is an. info file in D7. This file records the meta-information of the module. is the most basic information.
Name of the module, what is the description of the description module. Which group the package belongs to. such as belong to the Core
D8 kernel module.
The type can be module,theme or profile.
Name: Hello World moduledescription: Creates a page showing "Hello World". Package: customtype: moduleversion: 1.0Core: 8.x
Composer.json
New Composer.json
{ "name": "Drupal/example", "description": "This is a example Composer.json for example module.", "type": "Drupal-module", " License": "gpl-2.0+"}
Add Controller
Create a new/src/controller/hellocontroller.php in the Hello_world directory
<? php /* * * @file * Contains \drupal\hello_world\controller\hellocontroller. */ namespace Drupal\hello_world\controller; use Drupal\core\controller\controllerbase; class Hellocontroller extends Controllerbase { public function content () { return array ( ' #type ' = ' markup ', ' #markup ' = ' t ' (' Hello, world! '), ?
Returns the new HELLO_WORLD.ROUTING.YML in this module directory
Hello_world.content: path: '/hello ' defaults: _controller: ' \drupal\hello _world\controller\hellocontroller::content ' _title: ' Hello World ' requirements: _permission: ' Access content '
In this case, the module is completed, the opening address/hello will appear on the individual page of Hello World.
DRUPAL8 Create a new first module