nid never makes it to custom hook_nodecarousel function
| Project: | Nodecarousel |
| Version: | 6.x-1.x-dev |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
Jump to:
I am attempting to insert a node carousel onto an 'article' page [content type = article]. I am utilizing the hook_nodecarousel() function with my own custom version in a custom module. Since the 'article' is actually a node, the nodecarousel needs to get the nid so that it displays the correct image gallery in the carousel.
Whether I add a block to a region or if I invoke the block within the template itself, the nid is never making it to my custom function.
I know that my function is getting called. I also know that $nid is always -1. This is the case whether I'm using a normal block or if I'm invoking the block. When looking at the nodecarousel.module code, it looks like _nodecarousel_write_block() function isn't even looking for the nid let alone passing it along to the _nodecarousel_get_nodes() function.
Shouldn't the _nodecarousel_write_block() function be looking for the nid and passing it on since the hook_nodecarousel() function takes nid as an optional parameter?

#1
I looked around at some other modules, and made some changes, and now the nid is being passed along. But I don't know if the changes that I made are the correct ones or not.
I modified 2 functions: nodecarousel_block() and _nodecarousel_write_block().
In reference to nodecarousel_block(), I made a change to the "view" case. It gets the nid from the q parameter in the GET string. If it isn't numeric, it sets it to -1, and then it passes it on to the next function. The function I'm using now is as follows.
<?php
function nodecarousel_block($op = 'list', $delta = 0, $edit = array()) {
switch ($op) {
case 'list':
$blocks = array();
$query = "SELECT name, description, cache FROM {nodecarousel} ";
$result = db_query($query);
while ($row = db_fetch_object($result)) {
$blocks['nc_'. $row->name] = array('info' => $row->description ? $row->description : $row->name, 'cache' => $row->cache );
}
return $blocks;
break;
case 'view':
$nid = preg_replace('!^node/!', '', $_GET['q']);
if(!is_numeric($nid))
$nid = -1;
return _nodecarousel_write_block($delta, $nid);
break;
}
}
?>
In reference to _nodecarousel_write_block(), it is now taking an optional parameter passed in and passing it on to _nodecarousel_get_nodes(). The modified function is as follows.
<?php
function _nodecarousel_write_block($nc_name, $nid = -1) {
$nc = nodecarousel_load(substr($nc_name, 3));
if (!$nc) {
return NULL;
}
global $user;
if (!$user->roles) {
return NULL;
}
if (!nodecarousel_access($nc)) {
return NULL;
}
jcarousel_add(FALSE);
drupal_add_css(drupal_get_path('module', 'nodecarousel') .'/nodecarousel.css');
$node_array = _nodecarousel_get_nodes($nc, 0, $nid);
if (count($node_array) > 0) {
drupal_add_js(get_jcarousel_initialization_block($nc, $node_array), 'inline');
$themed_carousel = theme('nodecarousel', $nc, $node_array);
}
else {
$themed_carousel = "No items found.";
}
//Used for delayed load testing.
//$themed_carousel .= "<button type=button name=testbutton onclick='nc_load_$nc->name();'>Load</button>";
$block = array();
$block['title'] = $nc->title;
$block['content'] = $themed_carousel;
return $block;
}
?>
I'm new to Drupal and this is my first attempt at digging into the module code. As such, I'm not sure if my changes are the best way to go about things, but they're getting the job done.
#2
Just wondering if anyone has had a chance to look this over. Anyone??
#3
Hi there.
I'm not really maintaining this module anymore, and these days it's been pretty well overtaken and replaced by the Views Carousel module - I suggest giving that a try and seeing if it solves your problem.
#4
Thanks. I had no idea this module wasn't being maintained any more or that there was the Views Carousel module. I'll check it out.