Skip to content

Instantly share code, notes, and snippets.

@danreb
Last active May 1, 2019 14:27
Show Gist options
  • Save danreb/f5a55c599027aae6eee4 to your computer and use it in GitHub Desktop.
Save danreb/f5a55c599027aae6eee4 to your computer and use it in GitHub Desktop.
Anatomy of Drupal 7 Module
======== ANATOMY OF DRUPAL 7 MODULE ===============
1.) Required Files
module_name.info = Tells Drupal the information about your module (http://drupal.org/node/542202 - writing module info file)
module_name.module = Contains all hooks and functions related to module functionality
2.) Optional Files
module_name.install = Contains schema api hooks for creating and updating tables necessary for you module functionality
module_name_include.inc = Contains any PHP code you wish to includes necessary for your module functionality
module_name.css = Contains your module stylesheets code
module_name.js = Contains your module javascript code
3.) Optional Folders
css = To organize your CSS files if you need to include several css files in your module
js = To organize your JS files if you need to include several js files in your module
images = Contains all the images assets for your module.
4.) Where to put your modules?
- You can drop and put your modules inside the directory "sites/all/modules/custom" or "sites/default/modules/custom"
/* OK, your module CSS code goes here */
name = Your Module Name
description = Demonstrate how Drupal 7 module works.
core = 7.x
; Optional inforation below
;package = custom
;dependencies[] = views
;configure = admin/config/my_module/settings
;stylesheets[all][] = my_module.css
;scripts[] = my_module.js
<?php
/**
* @file
* Contains install and update functions for your module.
*/
/**
* Implements hook_install().
*/
function module_name_install() {
drupal_set_message(t('Your module has been installed. Horray!!!'));
}
/**
* Implements hook_uninstall().
*/
function module_name_uninstall() {
drupal_set_message(t('Oh men, your module has been uninstalled! So SAD!'));
}
(function ($, Drupal) {
'use strict';
Drupal.behaviors.ModuleName = {
attach: function (context, settings) {
// OK put your JS code below this.
}
}
}(jQuery, Drupal));
<?php
/*
* @file
* Contains all hooks and functions related to your module functionality
*
*/
<?php
/**
* @file
* Contains any PHP code you wish to includes necessary for your module functionality.
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment