{"id":63,"date":"2011-02-02T12:21:48","date_gmt":"2011-02-02T12:21:48","guid":{"rendered":"http:\/\/wordpress.agileadam.com\/?p=63"},"modified":"2014-01-22T00:19:05","modified_gmt":"2014-01-22T05:19:05","slug":"creating-a-module-d6","status":"publish","type":"post","link":"https:\/\/agileadam.com\/2011\/02\/creating-a-module-d6\/","title":{"rendered":"Creating a Module (D6)"},"content":{"rendered":"

This example shows how to create a custom module for a site. We typically create\u00a0one<\/strong>\u00a0custom catch-all module that we can use for one-off site customizations where we don’t need to create a unique module. If they are general site tweaks that cannot go in template.php, we put them here. Please read the book\u00a0Pro Drupal Development<\/em>\u00a0for a much better understanding of how all of this (and everything else Drupal) works!\u00a0DrupalBook.com<\/a>. It is an amazing reference tool for daily usage, as well as a complete walk-through of how to take advantage of the power of Drupal.
\n
\nPlease also visit\u00a0
http:\/\/drupal.org\/coding-standards<\/a>\u00a0if you plan on doing any coding in the Drupal environment (which is what you’re about to do if you read on)! There are\u00a0very<\/strong>\u00a0specific style guidelines, and some of them may take getting used to. For example, you must put a space before the { when you write a function (as shown below).<\/p>\n

Replace all instances of\u00a0mymodule<\/em>\u00a0with the name of your module.<\/strong>\u00a0We usually have a catchall module that contains the site name, like\u00a0amazonmods<\/em>\u00a0for example.<\/p>\n

Note: You are not limited to one custom module, but it’s probably best to keep “random tweaks” in a single module. If you need to make any more custom modules, be sure to put them in the same “package” (see the .info file) if they’re specific to the site.<\/p>\n

    \n
  1. Create a directory in\u00a0sites\/all\/modules<\/em>. Name this directory\u00a0_my_modules<\/em>.
    \n* this isn’t required, but makes things clean and easy to find<\/li>\n
  2. Create a directory in\u00a0sites\/all\/modules\/_my_modules<\/em>. Name the directory\u00a0mymodule<\/em>\u00a0(or whatever you choose for your module name.\u00a0Do NOT use underscores in your module name.<\/strong>\u00a0All examples on this site will use mysitemods as the module name unless otherwise noted.<\/li>\n
  3. Create a file in the\u00a0mysitemods<\/em>\u00a0directory called\u00a0mysitemods.info<\/em>. Use the example below to populate this file.\n
    ; $Id$\r\nname = MYSITE general modifications\r\ndescription = General modifications for the MYSITE site.\r\ncore = 6.x\r\npackage = My Site<\/pre>\n

     <\/li>\n

  4. Create a file in the\u00a0mysite<\/em>\u00a0directory called\u00a0mysitemods.module<\/em>. Use the example below to populate this file. This will get your module started by creating just a few nodeapi operations.\u00a0If you use exactly what is shown below<\/strong>, you’ll know if your module is working because when you view anything with this module active, it will show a message on the screen.\n
    <?php\r\n\/\/ $Id$\r\n\/**\r\n * @file\r\n * This is a custom module for the MYSITE site.\r\n *\/\r\n\r\n\/**\r\n * Implementation of hook_form_alter()\r\n *\/\r\nfunction mymodule_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {\r\n  switch ($op) {\r\n    case 'insert':\r\n      break;\r\n    case 'update':\r\n      break;\r\n    case 'view':\r\n      drupal_set_message(t('Yes! Our custom module is working.'));\r\n      break;\r\n    }\r\n}<\/pre>\n<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"

    This example shows how to create a custom module for a site. We typically create\u00a0one\u00a0custom catch-all module that we can use for one-off site customizations where we don’t need to create a unique module. If they are general site tweaks that cannot go in template.php, we put them here. Please read the book\u00a0Pro Drupal Development\u00a0for a much better understanding of how all of this (and everything else Drupal) works!\u00a0DrupalBook.com. It is an amazing reference tool for daily usage, as well as a complete walk-through of how to take advantage of the power of Drupal.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[79],"tags":[84,85,20],"_links":{"self":[{"href":"https:\/\/agileadam.com\/wp-json\/wp\/v2\/posts\/63"}],"collection":[{"href":"https:\/\/agileadam.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/agileadam.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/agileadam.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/agileadam.com\/wp-json\/wp\/v2\/comments?post=63"}],"version-history":[{"count":3,"href":"https:\/\/agileadam.com\/wp-json\/wp\/v2\/posts\/63\/revisions"}],"predecessor-version":[{"id":231,"href":"https:\/\/agileadam.com\/wp-json\/wp\/v2\/posts\/63\/revisions\/231"}],"wp:attachment":[{"href":"https:\/\/agileadam.com\/wp-json\/wp\/v2\/media?parent=63"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/agileadam.com\/wp-json\/wp\/v2\/categories?post=63"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/agileadam.com\/wp-json\/wp\/v2\/tags?post=63"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}