DRUPAL8 Create a new first module

Source: Internet
Author: User
Tags drupal

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.