跳转到主要内容
长风 提交于 8 February 2017

翻译者:长风Drupal开发

翻译地址:Drupal8创建自定义模块

原文地址:www.drupal.org/docs/8/creating-custom-modules

 

本指南包括您创建Drupal8模块需要教程和其他信息。

其他资源:

 

1、入门-背景与前提(Drupal 8)(已翻译)

为了适应第三方开发者,Drupal8利用高级PHP语言的特点和复杂的第三方库

2、准备模块骨架(已翻译)

在本指南的子章节之后,我们将构建不同的东西,自定义页面,块,实体,字段等。

3、命名和保存你的Drupal8模块(已翻译)

主题描述:模块命名和模块位置

4、通过.info.yml文件,让Drupal8识别你的模块(已翻译)

主题描述:模块的元数据

5、创建一个composer.json文件(已翻译)

composer.json文件能被添加到你的模块中,用来定义项目本身。你可以为你的模块定义额外的依赖关系

6、创建一个显示“hello word”的自定义页面(已翻译)

接下来的章节将带你创建一个简单模块,

7、添加基本的controller(已翻译)

当路由系统调用这个页面,在helloController类中的content()函数将返回内容和标识。

8、添加一个路由文件(已翻译)

回到你的模块的根目录,也就是.info.yml所在的位置,添加一个名为hello_world.routing.yml的新文件

9、创建一个菜单链接(已翻译)

现在我们已经为我们的模块创建了一个占位符,让我们为它添加一个菜单链接。

10、高级部分(已翻译)

For the truly adventurous, these code examples are the abridged version of the full page example from the Examples module.

11、在自定义模块中创建自定义区块(已翻译)

Contrary to Drupal 7, creating multiple instances of a block to place on your site is the second easiest example of module creation

12、创建一个自定义区块(已翻译)

Blocks in Drupal 8 are instances of the block plugin.

13、在区块配置中添加一个表单(已翻译)

Now let us say that we want to add the ability for the site builder to enter a piece of configuration for each instance of our custom block.

14、处理区块的设置表单(已翻译)

Add the following method to the HelloBlock class. In this example, it is located in the src/Plugin/Block/HelloBlock.php file, but as you

15、在区块显示中使用配置(已翻译)

To make use of the configuration of instances of the block, we can modify the build() method of the HelloBlock class:

16、添加一个默认的配置信息

By adding a single settings yaml file to our module, Drupal will automatically load the contents of that yaml file, and we can access it to

17、在模块中引用默认的配置信息

Main topic described: default configuration

18、添加样式和脚本到Drupal8模块中

This documentation is for modules. For the themes, see Adding stylesheets (CSS) and JavaScript (JS) to a Drupal 8 theme.

19、练习创建一个drupal8模块

From .info to tests, just the basics

20、基本架构

Basic structure

21、配置

Everything's pretty neat so far, but how do we change what we're seeing? With some forms, of course. /src/Form/LoremIpsumForm.php

22、样式

loremipsum.module

23、定义一个区块

Remember at the beginning of this tutorial when I said we'd define a block with a form? Well, now's the time to get right on it.

24、测试

Finally for some QA. Let's check that our module works as expected by writing a few tests of our own which can be run via Drupal itself.

25、创建一个自定义内容,配置entity

This explains how to create a node-like entity in Drupal 8. That means that we'll create one configuration entity(FooType) which will serve

26、在Drupal8中定义和使用你自己的配置信息

Main topic described: defining own configuration

27、创建一个自定义字段

In this guide we will go through the following topics:

28、创建一个自定义字段类型

Field types define the properties and behaviours of fields

29、创建一个自定义字段的样式

The field formatter formats the field data to be viewed by the end user.

30、创建一个自定义字段的显示

Field widgets are used to render the field inside forms.

31、创建一个自定义页面

在Drupal中创建一个简单的页面需要两步。

32、为Drupal8创建一个views的现实插件

Creating a Views display style plugin might seem like an intricate task, but it's easier than it looks. Here's a step by step guide on how