Community

Small menu module not being placed in correct region via context

Hi,

I am learning how to make modules and have hit a stumbling block already. It's very experimental to say the least and it's just a little menu with general admin things. The good news is that the menu works, bad news is I can't place it properly through context. It doesn't appear in my sidebar region, just sits at the top of the page instead. Here it is:

<?php
/**
* @file
* A block module to display common client links
*/

/**
* Implements hook_help.
*
* Displays help and module information.
*
* @param path
* Which path of the site we're using to display help
* @param arg
* Array that holds the current path as returned from arg() function
*/

function client_menu_help($path, $arg) {
switch ($path) {
case "admin/help#client_menu";
return '<p>' . t("Displays common links for clients to add/edit content") . '</p>';
break;
}
}

function client_menu_block_info() {
$blocks['client_menu'] = array(
'info' => t('Custom client menu'), // Name that appears in block list
'cache' => DRUPAL_CACHE_PER_ROLE, // Default
);
return $blocks;
}

/**
* Custom content function.
*
* The links
*
* @return
*   A client links menu.
*/

function client_menu_block_view($delta = '') {
switch($delta){
case 'client_menu';
$block['subject'] = t('Client menu');
if(user_access('access content')){

global $user;

if ($user->uid) {
echo '<ul class="menu">';

echo '<li>';
print l( 'Content overview', 'admin/content' );
echo '</li>';

echo '<li>';
print l( 'Add content', 'node/add' );
echo '</li>';

if (arg(0) == 'node' && is_numeric(arg(1))) {
echo '<li>';
print l( 'Edit this page', 'node/' . arg(1) . '/edit' );
echo '</li>';
}

echo '<li>';
print l( 'My account', 'user' );
echo '</li>';

echo '<li>';
print l( 'Logout', 'user/logout' );
echo '</li>';

echo '</ul>';
}
}
}
}

Does this need to be passed through the theme or something before it can be placed in a region?

Not really looking for an outright solution, just a pointer in the right direction would be more helpful. Thanks for any info.

Sam.

**edit**

on checking the page source code, it's appearing at the very top of the page, above the head section (!!), but is rendering as expected.

<ul class="menu"><li><a href="/admin/content">Content overview</a></li><li><a href="/node/add">Add content</a></li><li><a href="/node/2/edit">Edit this page</a></li><li><a href="/user">My account</a></li><li><a href="/user/logout">Logout</a></li></ul>

Comments

You shouldn't use echo and

You shouldn't use echo and print in hook_block_view.

Instead you should add the block content to $block['content'] and then return $block.

Use theme_item_list and/or render array to set $block['content']. (there is an example under the render array link, search for '#theme' => 'item_list',)

Hi, thanks. I am just getting

Hi, thanks. I am just getting started on the module development and could do with all the help I can get.

Sam.