06. Installing, enabling and testing the module

Last modified: January 5, 2008 - 23:02

At this point, you can install your module and it'll work. Let's do that, and see where we need to improve the module.

Install

To install the module, you'll need to copy your onthisdate.module file to the modules directory of your Drupal installation (which itself can be a subdirectory of your Drupal install or a subdirectory of sites/all or if you are coding a site specific module for a multisite install then sites/hostname). The file must be installed in this directory or a subdirectory of the modules directory, and must have the .module name extension and must have a correspoding .info file.

Enable

Log in as your site administrator, and navigate to the modules administration page to get an alphabetical list of modules. In the menus: Administer » Site building » Modules, or via URL:

  • http://example.com/admin/build/modules
  • http://example.com/?q=admin/build/modules

When you scroll down, you'll see the onthisdate module listed with the description next to it. Enable the module by selecting the checkbox and save your configuration.

Configure

Because the module is a blocks module, we'll need to also enable it in the blocks administration menu and specify a location for it to display. Node modules may or may not need further configuration depending on the module. Any module can have settings, which affect the functionality/display of a module. We'll discuss settings later. For now, navigate to the blocks administration page: admin/build/block or Administer » Site building » Blocks in the menus.

Enable the module by selecting the enabled checkbox for the 'On This Date' block and save your blocks. Be sure to adjust the location (left/right) if you are using a theme that limits where blocks are displayed.

Now, head to another page, say, select the modules menu. In some themes, the blocks are displayed after the page has rendered the content, and you won't see the change until you go to new page.

Test

If you have content that was created a week ago, the block will display with links to the content. If you don't have content, you'll need to fake some data. You can do this by creating a blog, forum topic or book page, and adjust the "Authored on:" date to be a week ago.

Alternately, if your site has been around for a while, you may have a lot of content created on the day one week ago, and you'll see a large number of links in the block.

Not listed on the Modules page

tkoterwas - September 29, 2008 - 13:23

I've uploaded both onthisdate.module and onthisdate.info to sites/all/modules/onthisdate. However, the module is not listed on my Modules admin page for enabling.

I've looked this tutorial over a dozen times, checked the files line by line, compared it to other .module and .info files, started from scratch, and then copied and pasted the code exactly, but I cannot seem to find the issue. I am able to install other modules just fine. I am using Drupal 6.4. PHP 5.2.6

any suggestions?

onthisdate.info:

; $Id$
name = On this date
description = A block module that lists links to content such as blog entries or forum discussions that were created one week ago.
core = 6.x

onthisdate.module:

<?php
/**
* Display help and module information
* @param path which path of the site we're displaying help
* @param arg array that holds the current path as would be returned from arg() function
* @return help text for the path
*/
function onthisdate_help($path, $arg) {
  $output = '';
  switch ($path) {
    case "admin/help#onthisdate":
      $output = '<p>'.  t("Displays links to nodes created on this date") .'</p>';
      break;
  }
  return $output;
} // function onthisdate_help


/**
* Valid permissions for this module
* @return array An array of valid permissions for the onthisdate module
*/

function onthisdate_perm() {
  return array('access onthisdate content');
} // function onthisdate_perm()


function onthisdate_block($op='list', $delta=0) {
  // listing of blocks, such as on the admin/block page
  if ($op == "list") {
    $block[0]["info"] = t("On This Date");
    return $block;
  } else if ($op == 'view') {
  // our block content
    // content variable that will be returned for display
    $block_content = '';

    // Get today's date
    $today = getdate();

    // calculate midnight one week ago
    $start_time = mktime(0, 0, 0,$today['mon'],
                               ($today['mday'] - 7), $today['year']);

    // we want items that occur only on the day in question, so
    //calculate 1 day
    $end_time = $start_time + 86400;
    // 60 * 60 * 24 = 86400 seconds in a day

    $result =  db_query("SELECT nid, title, created FROM {node} WHERE created >= '%s' AND created <= '%s'", $start_time, $end_time);
    while ($links = db_fetch_object($result)) {
      $block_content .= l($links->title, 'node/'.$links->nid) . '<br />';
    }
    // check to see if there was any content before setting up the block
    if ($block_content == '') {
      // no content from a week ago, return nothing.
      return;
    }
    // set up the block
    $block['subject'] = 'On This Date';
    $block['content'] = $block_content;
    return $block;
  }
}

OK for me

thisportrait - October 3, 2008 - 00:16

Hi,

on my system, it comes up as normal, in the 'Other' group of modules.

 
 

Drupal is a registered trademark of Dries Buytaert.