Hi there,
I thought it would be a good thing if I could display the related content in a block, so I've patched your module.
Perhaps you would like to add this functionality to the module ? I'd be happy. :-)
The patch is working for me, but please review my code, I think it's better when at least two people have checked it.
I did NOT change the help so far, this has still to be done.
Description:
With this patch you have to activate "administer related content" under "administer-> user management -> access control". Then you can access the "related content" settings under "administer -> site configuration". Choose the "The related content is shown in a block." radio button. You then can choose the block position under "administer-> site building -> blocks".
There is also a new themable function relatedcontent_asblock for themeing the block content.
/**
* Themeable function for displaying the body and the nodes.
*/
function theme_relatedcontent($body, $nodes) {
if ('0'==variable_get('relatedcontent_display_settings', 0)){
if ($nodes) {
foreach ($nodes as $node) {
$groups[$node->type][] = $node;
}
foreach ($groups as $type => $group) {
$body .= "<div class=\"relatedcontent-nodes $type\">\n";
$body .= "<h3>$type</h3>\n";
foreach ($group as $node) {
$body .= node_view($node, true);
}
$body .= "</div>\n";
}
}
}
return $body;
}
/**
* Themeable function for displaying the nodes in a block.
*/
function theme_relatedcontent_asblock ($nodes) {
if ($nodes) {
foreach ($nodes as $node) {
$groups[$node->type][] = $node;
}
foreach ($groups as $type => $group) {
$body .= "<div class=\"relatedcontent-nodes $type\">\n";
$body .= "<h3>$type</h3>\n";
foreach ($group as $node) {
$body .= node_view($node, true);
}
$body .= "</div>\n";
}
}
return $body;
}
/**
* Implementation of hook_menu().
*/
function relatedcontent_menu($may_cache) {
$items = array();
$access = user_access('administer related content');
if ($may_cache) {
$items[] = array('path' => 'admin/settings/relatedcontent',
'title' => t('Related Content'),
'description' => t('Configure if related content is added to the node or provides a block.'),
'callback' => 'drupal_get_form',
'callback arguments' => 'relatedcontent_settings',
'access' => $access);
}
else {
$base = drupal_get_path('module', 'relatedcontent');
drupal_add_css($base .'/relatedcontent.css');
}
return $items;
}
/**
* Implementation of hook_block().
*/
function relatedcontent_block($op = 'list', $delta = 0, $edit = array()) {
switch ($op) {
case 'list':
$blocks=array();
if ('1'==variable_get('relatedcontent_display_settings', 0)){
$blocks[0]['info'] = t('Related content');
}
return $blocks;
case 'configure':
return;
case 'save':
return;
case 'view': default:
switch ($delta) {
case 0:
if ('1'==variable_get('relatedcontent_display_settings', 0)){
$block['subject'] = t('Related content');
$block['content'] = _relatedcontent_get_block_content();
}
break;
}
return $block;
}
}
/**
* Add RelatedContent to the block.
*/
function _relatedcontent_get_block_content() {
if ( arg(0) == 'node' && is_numeric(arg(1)) && ! arg(2) ) {
$node = node_load(arg(1));
if (!$teaser) {
foreach ($node->nodes as $nid) {
$nodes[] = node_load($nid);
}
return theme(relatedcontent_asblock, $nodes);
}
}
}
/**
* Implementation of hook_perm().
*/
function relatedcontent_perm() {
return array('administer related content');
}
/**
* Admin settings form
*/
function relatedcontent_settings() {
$form = array();
$form['relatedcontent_config'] = array(
'#type' => 'fieldset',
'#title' => 'Related Content Block Settings',
);
$form['relatedcontent_config']['relatedcontent_display_settings'] = array(
'#type' => 'radios',
'#title' => t('Custom visibility settings'),
'#options' => array(
t('The related content is shown under the node.'),
t('The related content is shown in a block.'),
),
'#description' => t('Allow users to customize the visibility of the related content.'),
'#default_value' => variable_get('relatedcontent_display_settings', 0),
);
return system_settings_form($form);
}
| Comment | File | Size | Author |
|---|---|---|---|
| #1 | relatedcontent_with_block.patch | 4.26 KB | Andreas Wolf |
| withblocks.patch | 4.24 KB | Andreas Wolf |
Comments
Comment #1
Andreas Wolf commentedMh, found the first bug in my patch.
I upload the correct patch file.
Comment #2
TBarregren commentedThe idea to display the related content in a block instead of embedded into the node itself is an interesting extension of the RelatedContent module. I will probably go in that direction in a future version.
Next I will however focusing on two other features:
Don't despair, I have just released 5.x-1.4 which among many other small improvements includes an API with a singe function which can help you.
Following is from the new help text:
Application Programming Interface (API)
RelatedContent provides a very simple API that can be used by modules and themes, or within nodes or blocks with the PHP input filter, to get related content and do something clever with it. The API consists of the following function:
function relatedcontent(&$node, $output_grouped, $content_function, $content_function_args), where$nodeis either the id of a node (nid) or a node object as loaded by node_load().$output_groupedisfalseif the output should not be grouped, and'type'or'name'if the output should be grouped by content type or author, respectively.$content_functionis a callback function which given a node as the first argument and the values of$content_function_argsas arguments 2,3,... returns content to be outputted.$content_function_argsis an array with arguments 2,3,... to the callback function$content_function.The related content of
$nodeis returned as an associative array, whose keys are the names by which the output should be grouped, i.e. the name of content types or authors, depending on the settings, or'all'if grouping is disabled. Each output buffer is an ordinary array with the return value of the callback function$content_functionwith the node to be outputted as the first argument and the remaining arguments given by the array$content_function_args.The API function relatedcontent() can for instance be used to display the related content in a bock instead of within the node. Just add a block, enable the PHP input format, and paste following code snippet in the text area:
Comment #3
TBarregren commentedIn this comment I gave a complete example of using the API to accomplish a block with links to related content.
Comment #4
peter-boeren commentedA basic default block is now in the code of the Drupal 6 version. This block also shows the nodes in a themed item list.