As soon as you start developing reliable websites in Drupal 7, the need to create custom modules arises. There will be plenty of situations where you need to create custom hooks to handle certain business requirements for your Drupal website; and those hooks have to live inside a custom module. For example, check our previous post about preventing content deletion in certain cases in Drupal 7 which implements a custom hook.
There are plenty of resources online for learning how to create custom modules in Drupal 7. Here are a few of the most notable ones.
We couldn't however find a quick guide that lists the technical steps required to get a minimal module. This is why we wrote our own. In addition, we're attaching the custom module template to this post for your convenience. The download link is at the end of the tutorial.
Keep in mind we're creating a minimal Drupal 7 module. Basically, as minimal as we can get so that we have a base to start implementing custom PHP code functionality inside the module.
Let's assume your module will be called sk.
Open the sk.info file in a text editor and place the following inside it.
name = SK description = SOFTKUBE's Custom Drupal Module Template package = SOFTKUBE core = 7.x version = 7.x-1.0 files = sk.module
The final step is to activate the module from the Modules admin dashboard. Just login with your admin account, go to the modules administration page, search for your module, and activate it.
Now, all you have to do is write some custom PHP code inside the sk.module file. If you're eager to test something out, check our blog posts about Drupal or, for example, our blog post about conditionally preventing node deletion in Drupal, and you'll surely find some custom hooks to implement inside the sk.module file.
Don't forget to clear Drupal's cache when you implement hooks. Depending on the hook implemented, this might be necessary or optional so keep that in mind.
That's it. Happy coding.
Founder of SOFTKUBE, lead developer, and getting things done addict. Passionate about open source, user interface design, business development, and the tech world.
A small team of experts developing simple, usable, and high-quality web solutions. We blog about business, entrepreneurship, web development, and technology.
Business Cheat Sheets CLI Development Downloads Drupal Email Google Apps HID Keyboards Multilingualism Open Source Philosophy PHP Pointing Devices Quotes Science Security SEO Technology Thoughts Windows Zend Framework