Skip to main content

Drupal 8 Tutorials : Custom Module



Custom Module development in Drupal 8 is very simple. It may looks very difficult for developer who has Drupal 7 experience or nothing at all.

This tutorial will show easy steps and helps you to create custom module within few minutes.

Note:

Content or example of this tutorial may change according to Drupal 8 version and its release.

This tutorial is divided into three small sections.

In first section of this tutorial we will see what directory structure we need to create for a custom module.

In second section we will see what type files we need to create.

And in last section we will see what code we need to write in those files and configure them in Drupal 8.

1 Directory Structure


All custom module in Drupal 8 reside under “module” directory of Drupal 8 project.

To create a custom module we will create a new directory named “document” under custom folder.

Following is directory structure.







2 Configuration files

Second thing that we need to create is YAML files which represent custom module configurations.

Followings are files that you need to create.

  • {module name}.info.yml   i.e  document.info.yml
  • {module name}.module   i.e  document.module

only document.info.yml file is enough for configuring of document module.

Following is directory structure after including these files







3 Writing Configuration Settings

Add following code inside document.info.yml










Above configuration settings are very descriptive except only one parameter which is type.

As we are creating custom module therefore type parameter must be typed as module.

Now your module is ready to enable and use.

Go to Drupal Admin page and enable document module from

Admin->Extend link

Now search document module in search list

Then select check box before document module name and click “Save Configuration” button.

That’s it, custom document is now ready to use

Next tutorial will help you create custom controller for this custom module.

Comments

Subscribe for latest tutorial updates

* indicates required

Popular posts from this blog

AJAX - How To Retrieve JSON Response from PHP script

Hello Friends, This is my first tutorial post. Today I'll explain you how to retrieve JSON response via Ajax call. First we build a PHP script to send response in JSON format, then we will gather this response from an Ajax call through jQuery script. Let’s first create a PHP script  Create a PHP script, I’ll name it as “json_response.php” And add following code in it json_response.php <?php //set header for JSON response header("Content-Type: application/json"); //render array in JSON format echo json_encode(array('status' => 200, 'message' => 'Response from PHP script in JSON format.')); This is a basic example to send JSON response. PHP script will send response with status code and message. Now create a HTML file to fetch JSON response and add it in header tag. Create a HTML file, I’ll name it as “json_response.html” And add following code. json_response.html <html>           ...

Twig Tutorials: Install and Configure

In this tutorial, we'll look at how to install Twig within your PHP project and thereafter configure it so that we can create and use a Twig template inside our PHP web application. Later on, we'll see a simple Twig template example that displays a "Welcome to Twig template" message. Let's take it one step at a time. Install The Twig template can be installed using Composer, Git, or PEAR. In this tutorial, we will use Composer to install Twig. To do so, we'll need to make a "composer.json" file. { "require" : { "twig/twig" : "1.*" } } From the console, run the following command . $ php composer.phar install This command will install Twig library. Configuration To use the Twig template, we should first configure it. To achieve this, we will write an index.php file which will configure the Twig autoloader and generate the Twig environment. We will render the Twig temp...

JAX-RS Tutorials: REST API using Java

JAX-RS is API specification   for RESTful web services using Java. RESTful web services is implementation of REST ( Representational State Transfer ) which is architectural design for distributed system or in general we can say JAX-RS  is a set of APIs to develop REST service.   This is a brief introduction about REST and JAX-RS. You can find more information on REST on Wiki and JAX-RS Official Site. What is REST? Representational state transfer is an abstraction of the architecture of the World Wide Web. More precisely, REST is an architectural style consisting of a coordinated set of architectural constraints (source  Wikipedia ) As JAX-RS is only a specification, we need to use it's implemented library to create RESTful web service. Following are such list of libraries Apache CXF , an open source  Web service  framework. Jersey , the reference implementation from  Sun  (now  Ora...