Heyho,

I'm starting to write a module for Drupal 7 according to the HOWTO here: http://drupal.org/node/206753, which is for drupal 6 though.

I created the .info and the .module file exactly as explained in the HOWTO, except that added
files[] = modulename.module
in the .info file to make my module show up in admin/modules (as explained here : http://drupal.org/node/785714)

The module shows up in admin/modules and I can activate it. But then on admin/structure/block the block created from the module is not there? Also it is not shown in the DB in table blocks, where, I guess, it shoul go?

Any help?

.info

; $Id$
name = met
description = mydesription
core = 7.x


files[] = met.module 

.module (exactly as in the HOWTO)

// $Id$

/**
* 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 met_help($path, $arg) {
  $output = '';  //declare your output variable
  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 met_perm() {
  return array('access met content');
} // function met_perm()



/**
* Implementation of hook_block().
* @param string $op one of "list", "view", "save" and "configure"
* @param integer $delta code to identify the block
* @param array $edit only for "save" operation
*/
function met_block($op = 'list', $delta = 0, $edit = array()) { 

	if ($op == "list") {
		// Generate listing of blocks from this module, for the admin/block page
		$block = array();
		$block[0]["info"] = t('met');
		return $block;
	}
	else if ($op == 'view') {

		// Generate our 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
		
		$end_time = time();

		$query = "SELECT nid, title, created FROM " .
			"{node} WHERE created >= '%d' " .
			" AND created <= '%d'";

		$query_result =  db_query($query, $start_time, $end_time);
		
		// check to see if there was any content before returning
		// the block view
		if ($block_content == '') {  
			// no content from a week ago
			$block['subject'] = 'met';
			$block['content'] = 'Sorry No Content';
			return $block;
		}

		// set up the block 
		$block = array();
			$block['subject'] = 'met'; 
			$block['content'] = $block_content;
			return $block;
		} 

} // function met_block

Comments

jayco33’s picture

I tried it now with a Drupal 6.17 installation and it worked as expected...the nee Block shows on admin/build/block

Is this a bug, or am I doing something therribly wrong?

thx

preenet’s picture

Drupal 7 use hook_block_info(), hook_block_view(), etc to replace the Drupal 6 hook_block()

mymodule.info:

;$Id$
name = my module
description = my drupal 7 module
core = 7.x
php = 5.1

files[] = mymodule.module

mymodule.module:

<?php
// $Id$

/**
 * Implements hook_block_info().
 */
function mymodule_block_info() {
  $blocks['recent']['info'] = t(' my first drupal 7 module');
  return $blocks;
}

/**
 * Implements hook_block_view().
 *
 */
function mymodule_block_view($delta = '') {
	$block = array();
	$block['subject'] = t('oh, my first drupal 7 module');
	$block['content'] = t('I will create my first module');
	return $block;
}
WorldFallz’s picture

I haven't had a chance to dive into d7 dev yet, but in general, there are major changes between major versions of drupal. Be sure to checkout http://drupal.org/update/modules/6/7 when developing for d7 whenever using d6 code.