Last active
May 1, 2019 14:27
-
-
Save danreb/f5a55c599027aae6eee4 to your computer and use it in GitHub Desktop.
Anatomy of Drupal 7 Module
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
======== 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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* OK, your module CSS code goes here */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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!')); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function ($, Drupal) { | |
'use strict'; | |
Drupal.behaviors.ModuleName = { | |
attach: function (context, settings) { | |
// OK put your JS code below this. | |
} | |
} | |
}(jQuery, Drupal)); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* @file | |
* Contains all hooks and functions related to your module functionality | |
* | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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