Drupal 7模块的框架结构是什么?


14

构建Drupal 7模块需要哪些文件?构造基本.info文件有哪些要求?这个问题的实质是为从头开始构建基本的Drupal 7模块提供框架。


如果您对问题不满意,请发布原因,以便解决。
Lester Peabody

Answers:


13

所需的最少文件数:

通常,模块所需的最少文件如下:

站点/所有/模块/ {您的模块名称}

  • {your module}.info
  • {your module}.module

或使用示例模块:

drupal.org上的示例模块为您提供了开发自定义/贡献模块的框架模块。只需使用它即可复制并创建您的模块。

签出项目页面

该项目旨在为各种Drupal核心功能提供高质量,文档齐全的API示例。

(是否对其他非核心示例感兴趣?)

通过试验这些示例,开发人员可以快速学习如何使用特定的API,并使其适合自己使用。

链接到git存储库:http : //drupalcode.org/project/examples.git/tree/refs/heads/7.x-1.x

来自示例模块的代码:

我还粘贴了您可以从示例模块中获得的代码。

example.info文件:

name = Examples For Developers
description = A variety of example code for you to learn from and hack upon.
package = Example modules
core = 7.x

example.module文件:

<?php

/**
 * @file
 * This file serves as a stub file for the many Examples modules in the
 * @link http://drupal.org/project/examples Examples for Developers Project @endlink
 * which you can download and experiment with.
 *
 * One might say that examples.module is an example of documentation. However,
 * note that the example submodules define many doxygen groups, which may or
 * may not be a good strategy for other modules.
 */

/**
 * @defgroup examples Examples
 * @{
 * Well-documented API examples for a broad range of Drupal 7 core functionality.
 *
 * Developers can learn how to use a particular API quickly by experimenting
 * with the examples, and adapt them for their own use.
 *
 * Download the Examples for Developers Project (and participate with
 * submissions, bug reports, patches, and documentation) at
 * http://drupal.org/project/examples
 */

/**
 * Implements hook_help().
 */
function examples_help($path, $arg) {
  // re: http://drupal.org/node/767204
  // 5. We need a master group (Examples) that will be in a main
  // examples.module.
  // The examples.module should be mostly doxy comments that point to the other
  // examples.  It will also have a hook_help() explaining its purpose and how
  // to access the other examples.
}

/**
 * @} End of 'defgroup examples'.
 */

8

1)确定模块的名称(例如:mymodule)。

2)使用您的模块名称在site / all / modules中创建一个文件夹。

3)在文件夹中,创建一个带有开头php标签(<?php)的mymodule.module文件- ?>应该省略结束标签()。

4)用以下3行创建一个mymodule.info文件(在模块的文件夹内):

 name = Mymodule
 description = Description for the module
 core = 7.x

有了这个,您已经有了可以通过GUI启用的Drupal 7模块(只要您没有在mymodule.module文件中添加任何功能/代码,它就不会做任何事情)。请注意,此处使用的所有mymodule实例均应替换为实际模块的名称,并且“模块描述”应为正确的描述。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.