Drupal modules, how to write your own module
Drupal is quite rich in its basic functionality. From version to version, new features were periodically included in the kernel and unnecessary ones were removed, as, incidentally, this happens in all software products. You can expand the functionality using modules.
What is a module? This is a separately rendered code, which is formatted and structured in a certain way. In other systems, such units of code are called plugins, add-ons, extensions, etc., Drupal decided to call them modules. Module for Drupal is designed as a simple folder where the necessary files are located.
To expand the functionality of the system, you can use the standard modules that come with the Drupal core, you can also download any modules from the official website. But if you have reviewed all the modules and did not find the right one, then it is worth developing your own module for Drupal . This is an easy process if you have basic knowledge of Drupal and PHP.
Where are Drupal modules located ? The modules supplied with the kernel are located in the / modules folder at the root of the site. Modules that are downloaded and connected separately must be placed only in the / sites / all / modules / folder, or it can be / sites / site-name / modules / - in case of multisiting. After placing it in the folder, the module must be enabled in the Drupal settings, from this moment the module code will be used during the system operation. Drupal has its own internal scheme for connecting modules, which, with each page request, checks for the presence of modules and their activation, after which functions from the module are called, hooks are executed, etc.
To develop your own module for Drupal , it is enough to look at a sample from any existing module, it is best to take a module with a small size as an example, so it will be easier to understand the structure of Drupal modules. The minimum number of module files is 2 files, this is a file with the extension * .info , which contains a description and a file * .module - it contains the functionality of the module, which is written in accordance with with Drupal API .
A small example, let's say a module for Drupal 7 is called Module, then in the module folder you need to create a module.info file with the following content:
name = Name
description = Description
package = Package
core = 7.x
version = "7.x-1.00"
Everything is intuitive here, the name, description, package, kernel version and module version are listed. The key is on the left, and the values are on the right. Next, create a module.module file, in which you can write the required functionality, all functions must begin with the module_ prefix.
Thus, developing a Drupal module is an easy task that almost anyone can do. In more detail, the procedure for creating a module with an example will be discussed in the following articles.
- 09.11.23IT / Database Errors when migrating from MySQL 5.6 to 5.7 and how to fix them - database dump import failed with an error or INSERT does not work. Disabling STRICT_TRANS_TABLES strict mode or using IGNORE
- 09.07.22IT / Misc Convert office files DOC, DOCX, DOCM, RTF to DOCX, DOCM, DOC, RTF, PDF, HTML, XML, TXT formats without loss and markup changes
- 07.07.22IT / Safety How to protect PHP, JS, HTML, CSS source code - obfuscation, minification, compression and encryption
- 06.07.22IT / Safety Connection not secure, problem with Lets Encrypt - how to fix expired 09/30/2021 DST Root CA X3, remove it manually and install ISRG Root X1. Example on MS Windows 7
- 08.07.21IT / Misc How to make a free translation for a website without an API, translate documents in Google Translate