<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="https://script.spoken-tutorial.org/skins/common/feed.css?303"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>https://script.spoken-tutorial.org/index.php?action=history&amp;feed=atom&amp;title=Drupal%2FC4%2FCreating-a-simple-custom-module%2FEnglish-timed</id>
		<title>Drupal/C4/Creating-a-simple-custom-module/English-timed - Revision history</title>
		<link rel="self" type="application/atom+xml" href="https://script.spoken-tutorial.org/index.php?action=history&amp;feed=atom&amp;title=Drupal%2FC4%2FCreating-a-simple-custom-module%2FEnglish-timed"/>
		<link rel="alternate" type="text/html" href="https://script.spoken-tutorial.org/index.php?title=Drupal/C4/Creating-a-simple-custom-module/English-timed&amp;action=history"/>
		<updated>2026-04-22T10:48:47Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.23.17</generator>

	<entry>
		<id>https://script.spoken-tutorial.org/index.php?title=Drupal/C4/Creating-a-simple-custom-module/English-timed&amp;diff=43241&amp;oldid=prev</id>
		<title>PoojaMoolya: Created page with &quot; {| border = 1 |  &lt;center&gt;Time&lt;/center&gt; |  &lt;center&gt;Narration&lt;/center&gt;  |- | 00:01 |  Welcome to the spoken tutorial on''' Creating a simple custom module'''.  |- |  00:06 |  I...&quot;</title>
		<link rel="alternate" type="text/html" href="https://script.spoken-tutorial.org/index.php?title=Drupal/C4/Creating-a-simple-custom-module/English-timed&amp;diff=43241&amp;oldid=prev"/>
				<updated>2018-05-23T09:15:39Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;quot; {| border = 1 |  &amp;lt;center&amp;gt;Time&amp;lt;/center&amp;gt; |  &amp;lt;center&amp;gt;Narration&amp;lt;/center&amp;gt;  |- | 00:01 |  Welcome to the spoken tutorial on&amp;#039;&amp;#039;&amp;#039; Creating a simple custom module&amp;#039;&amp;#039;&amp;#039;.  |- |  00:06 |  I...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&lt;br /&gt;
{| border = 1&lt;br /&gt;
|  &amp;lt;center&amp;gt;Time&amp;lt;/center&amp;gt;&lt;br /&gt;
|  &amp;lt;center&amp;gt;Narration&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 00:01&lt;br /&gt;
|  Welcome to the spoken tutorial on''' Creating a simple custom module'''.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  00:06&lt;br /&gt;
|  In this tutorial, we will learn to-  Create a basic '''module'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 00:11&lt;br /&gt;
|   Add a basic '''controller''' and&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 00:13&lt;br /&gt;
|   Add a '''routing''' file&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  00:15&lt;br /&gt;
|  To record this tutorial, I am using  '''Ubuntu Linux 16.04''' &lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 00:21&lt;br /&gt;
|   '''Drupal 8 ''',   '''Firefox web browser '''and  '''Gedit text editor'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 00:27&lt;br /&gt;
|  You can use any text editor and web browser of your choice.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  00:32&lt;br /&gt;
|  To practise this tutorial, you should have basic knowledge of''' Drupal'''.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 00:38&lt;br /&gt;
|  If not, for relevant''' Drupal''' tutorials, please visit the link shown.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 00:43&lt;br /&gt;
|  To create a '''custom module''' in '''Drupal''', you should be familiar with&lt;br /&gt;
&lt;br /&gt;
'''Object oriented programming terminology'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 00:51&lt;br /&gt;
|   Programming in '''PHP''' &lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 00:53&lt;br /&gt;
|   '''Namespacing''' in '''PHP '''and&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 00:55&lt;br /&gt;
|   '''Symfony 2'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 00:57&lt;br /&gt;
|  For details of pre-requisites, please see the “'''Additional reading material'''” link of this tutorial. &lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  01:04&lt;br /&gt;
|  We have already learnt about '''contributed modules '''earlier.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 01:08&lt;br /&gt;
|  Now we will learn to create a simple '''custom module'''.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 01:12&lt;br /&gt;
|  This '''module '''will create a '''custom page '''showing “'''hello world'''”.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 01:17&lt;br /&gt;
|  Here is the '''workflow '''of this '''module'''. &lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 01:20&lt;br /&gt;
|  The '''Request''' is what we request to the website.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 01:24&lt;br /&gt;
|  '''Router''' determines what should be done with the '''request'''.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 01:29&lt;br /&gt;
|  The '''controller''' builds the response for the given '''request'''.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 01:33&lt;br /&gt;
|  The '''View''' creates the response.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 01:36&lt;br /&gt;
|  The '''response''' is what the website returns. &lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  01:40&lt;br /&gt;
|  Here is the file structure of the '''custom module''' which we are going to create.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  01:45&lt;br /&gt;
|  Let us start creating the files required for a '''custom module'''.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 01:50&lt;br /&gt;
|  Open your '''File browser.'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  01:52&lt;br /&gt;
|  Go to the folder where we have installed '''Drupal''' locally.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  01:57&lt;br /&gt;
|  Now go to '''apps -&amp;gt; drupal -&amp;gt; htdocs -&amp;gt; modules '''folder'''.'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 02:03&lt;br /&gt;
|  We have to always create our''' custom modules''' inside this '''modules''' folder.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  02:09&lt;br /&gt;
|  Let’s create a folder and name it as '''custom'''.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 02:13&lt;br /&gt;
|  This will separate our '''custom modules''' from the '''contributed modules'''. &lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  02:18&lt;br /&gt;
|  Inside this '''custom''' folder, we will create a folder called '''hello_world'''. &lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  02:25&lt;br /&gt;
|  This folder name is the '''machine name. '''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 02:28&lt;br /&gt;
|  It will be used by '''core''' '''Drupal''', to refer to this '''module'''.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  02:33&lt;br /&gt;
|  There are some rules to follow when naming a '''custom module'''.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 02:37&lt;br /&gt;
|   It must contain only lower-case letters, underscores but no spaces. &lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 02:43&lt;br /&gt;
|   It must be unique and cannot have the same short name as any other module or theme&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 02:50&lt;br /&gt;
|   It cannot have any reserved terms such as '''src, lib, vendor, templates, includes, fixtures, '''etc.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 03:00&lt;br /&gt;
|  Switch back to our file browser&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 03:03&lt;br /&gt;
|  Inside this '''hello_world '''folder, we will create a file called '''hello_world '''with '''info.yml '''extension'''.'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 03:13&lt;br /&gt;
|  The name of the '''info.yml''' file and the name of the '''module''' folder should be the same.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  03:20&lt;br /&gt;
|  '''Yml''' is the file extension of '''YAML'''.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 03:24&lt;br /&gt;
|  '''YAML''' is a unicode based data serialization standard for all programming languages.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 03:31&lt;br /&gt;
|  It is a human-readable language.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 03:34&lt;br /&gt;
|  This '''info.yml '''file is to tell '''Drupal''' about our '''module'''.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 03:40&lt;br /&gt;
|  In this file, we will store the '''metadata''' of our '''module'''.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 03:44&lt;br /&gt;
|  So type the following '''metadata'''.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  03:47&lt;br /&gt;
|  Let's  save this file.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  03:49&lt;br /&gt;
|  This is the title of our '''module''' which will be shown on the '''extend''' page.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  03:54&lt;br /&gt;
|  This is a small description of our '''module'''.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 03:58&lt;br /&gt;
|  This is what category our '''module''' will be listed under on the '''extend''' page.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  04:04&lt;br /&gt;
|  This is to tell '''Drupal''' that we are making a '''module.'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  04:08&lt;br /&gt;
|  The '''core key''' specifies the version of '''Drupal core''' that our '''module''' is compatible with.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  04:15&lt;br /&gt;
|  Here '''name''', '''type''' and '''core keys''' are required. Other '''keys''' can be ignored.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  04:21&lt;br /&gt;
|  Next, we will create a file called '''hello_world''' with '''module''' extension.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 04:28&lt;br /&gt;
|  For this demonstration, we are not going to add any functionality in this file. &lt;br /&gt;
&lt;br /&gt;
But we just need to create this file.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 04:37&lt;br /&gt;
|  In this file, type the following.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  04:39&lt;br /&gt;
|  Let us save the file.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  04:41&lt;br /&gt;
|  These are the two files '''Drupal''' requires to create a '''module'''.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  04:46&lt;br /&gt;
|  Now we will install this '''module''' in our website.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 04:50&lt;br /&gt;
|  Open our local '''Drupal''' website.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 04:53&lt;br /&gt;
|  Before installing the new '''module''', we will clear the '''cache '''first.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 04:58&lt;br /&gt;
|  To do that, click on the '''Configuration '''menu'''.'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 05:01&lt;br /&gt;
|  Under '''Development''', click on the '''Performance '''option'''.'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  05:05&lt;br /&gt;
|  Now click on the '''Clear all caches''' button.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 05:08&lt;br /&gt;
|  You can see that the '''caches''' are cleared.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 05:11&lt;br /&gt;
|  It is compulsory to clear the '''caches''' every time we modify our website.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 05:17&lt;br /&gt;
|  Now to install the '''module''', click on the '''Extend '''menu and scroll down.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 05:23&lt;br /&gt;
|  Under '''Custom''', you can see the '''Hello World module '''which we created just now.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  05:28&lt;br /&gt;
|  Click on it to select.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 05:30&lt;br /&gt;
|  Click on the '''Install''' button at the bottom.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 05:33&lt;br /&gt;
|  Our''' custom module''' is enabled now.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  05:36&lt;br /&gt;
|  Next, we have to add the''' router file'''. &lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 05:40 &lt;br /&gt;
| This is to tell '''Drupal''' where the '''module''' can be accessed from. &lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 05:44&lt;br /&gt;
|  The '''router''' determines what should be done with the '''request'''.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 05:48&lt;br /&gt;
|  The '''router''' also checks if the access is permitted.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  05:53&lt;br /&gt;
|  Switch back to our '''File browser'''.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  05:55&lt;br /&gt;
|  Now we will create the routing file called '''hello_world.routing.yml'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  06:03&lt;br /&gt;
|  Type the following inside the routing file. Let us understand the code.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 06:08&lt;br /&gt;
|  This line is the '''route'''.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 06:10&lt;br /&gt;
|  This indicates what path will be used to access our '''module'''.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 06:15&lt;br /&gt;
|  This is to tell '''Drupal''' where to get the '''content''' from. &lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 06:20&lt;br /&gt;
|  Here '''content''' is the '''function '''which we will create in the '''controller '''file.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 06:25&lt;br /&gt;
|  This is to ensure only users who can access '''content,''' will be able to see our '''Hello World '''page.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  06:33&lt;br /&gt;
|  Next we should add the functionality about what this '''module '''is going to do.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 06:38&lt;br /&gt;
|  This is done by adding a '''controller'''.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 06:41&lt;br /&gt;
|  What is a '''controller'''? '''Controller''' is a '''PHP function. '''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 06:46&lt;br /&gt;
|  It takes information from the '''HTTP request '''and constructs and returns an '''HTTP response'''.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 06:54&lt;br /&gt;
|  Switch back to our '''File browser'''.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  06:56&lt;br /&gt;
|  To add a '''controller''', we should create a folder named '''src '''here. &lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  07:02&lt;br /&gt;
|  Inside the '''src''' folder, we should create another folder named '''Controller'''. &lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  07:07&lt;br /&gt;
|  Inside this '''Controller''' folder, we will create the controller file called '''HelloController.php'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  07:15&lt;br /&gt;
|  Inside this file, type the following.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  07:18&lt;br /&gt;
|  Now save the file.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  07:20&lt;br /&gt;
|  The '''namespace''' allows to place a bunch of code under a name, to avoid naming conflicts.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 07:28&lt;br /&gt;
|  This '''use statement''' will import the '''ControllerBase class'''.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 07:32&lt;br /&gt;
|  We have a '''class HelloWorldController '''with the function '''content.''' &lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 07:38&lt;br /&gt;
|  It will return the markup text when the routing system invokes the page.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  07:43&lt;br /&gt;
|  Now switch to the web browser.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 07:46&lt;br /&gt;
|  Click on the''' Back to site '''button.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 07:48&lt;br /&gt;
|  Add '''hello '''in the address bar as a '''request''' to the web browser. &lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 07:53&lt;br /&gt;
|  This is the path we created in the routing file to access our '''module'''. &lt;br /&gt;
&lt;br /&gt;
Now press''' Enter.'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 08:00&lt;br /&gt;
|  We can see our custom page which we created just now. This is the '''response'''.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  08:07&lt;br /&gt;
|  Likewise, we can create other simple '''custom modules''' in '''Drupal 8'''.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  08:13&lt;br /&gt;
|  With this, we come to the end of this tutorial.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  08:16&lt;br /&gt;
|  Let us summarize. In this tutorial, we have learnt to-&lt;br /&gt;
&lt;br /&gt;
Create a basic '''module''', Add a basic '''controller''',  Add a '''routing''' file&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 08:27&lt;br /&gt;
|  As an assignment, create a''' custom module''' for “'''About us'''” page of your website.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  08:33&lt;br /&gt;
|  The video at the following link summarises the Spoken Tutorial project.&lt;br /&gt;
&lt;br /&gt;
Please download and watch it.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 08:41&lt;br /&gt;
|  The Spoken Tutorial Project Team conducts workshops and gives certificates.&lt;br /&gt;
&lt;br /&gt;
For more details, please write to us.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  08:49&lt;br /&gt;
|  Spoken Tutorial Project is funded by  NMEICT, Ministry of Human Resource Development and NVLI, Ministry of Culture, Government of India.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  09:00&lt;br /&gt;
|  This is Priya from IIT Bombay signing off. Thanks for joining.&lt;br /&gt;
&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>PoojaMoolya</name></author>	</entry>

	</feed>