Commit aed1b0ca authored by Dries's avatar Dries

- Patch #5347 by JonBob:

Here's a new patch that unifies the node/52 and book/view/52 paths for nodes. It involves a small change to hook_view(), which is discussed first:

Currently hook_view() expects node modules to return a themed node. However, each module does this the same way; they modify $node as necessary, then call theme('node', $node) and return the result. We can refactor this so that the calling function node_view() calls theme('node') instead. By doing this, it becomes possible for hook_nodeapi('view') to be called after hook_view() where the node contents are filtered, and before theme('node') where the body is enclosed in other HTML. This way the book module can insert its navigation into the body right before the theming.

Advantages of this refactoring:
- I can use it for book.module to remove the extra viewing path.
- The function of hook_nodeapi('view') becomes more like hook_view(), as neither will expect a return value.
- We more closely follow the flow of other nodeapi calls, which usually directly follow their corresponding specific node type hooks (instead of preceding them).
- The attachment.module people could use it to append their attachments in a list after the node.
- Gabor could use it instead of his filter perversion for his "articles in a series" module.
- A little less code in each view hook.
- The content hook is no longer needed, so that means even less code.

Disadvantages:
- Any modules written to use nodeapi('view') could be affected (but these would all be post-4.4 modules).
- Implementations of hook_view() would need to be updated (but return values would be ignored, so most would work without updates anyway).

Now the patch takes advantage of this API shift to inject its navigation at the end of all book nodes, regardless of the viewing path. In fact, since the paths become identical, I've removed the book/view handler entirely. We should probably provide an .htaccess rewrite for this (one is still needed for node/view/nn anyway). At the same time, there is a check in book_block() that shows the block appropriately on these pages.
parent 6c73823b
......@@ -27,6 +27,8 @@ Drupal x.x.x, xxxx-xx-xx
* added 'categories' block.
- blogger API:
* added support for auto-discovery of blogger API via RSD.
- news aggregator:
* improved date parsing.
- performance:
* added support for sending gzip compressed pages.
- accessibility:
......
......@@ -227,7 +227,7 @@ function blog_content($node, $teaser = FALSE) {
/**
* Implementation of hook_view().
*/
function blog_view($node, $teaser = FALSE, $page = FALSE) {
function blog_view(&$node, $teaser = FALSE, $page = FALSE) {
if ($page) {
// Breadcrumb navigation
$breadcrumb[] = array('path' => 'blog', 'title' => t('blogs'));
......@@ -237,8 +237,6 @@ function blog_view($node, $teaser = FALSE, $page = FALSE) {
}
// prepare the node content
$node = blog_content($node, $teaser);
// print the node
return theme('node', $node, $teaser, $page);
}
/**
......
......@@ -227,7 +227,7 @@ function blog_content($node, $teaser = FALSE) {
/**
* Implementation of hook_view().
*/
function blog_view($node, $teaser = FALSE, $page = FALSE) {
function blog_view(&$node, $teaser = FALSE, $page = FALSE) {
if ($page) {
// Breadcrumb navigation
$breadcrumb[] = array('path' => 'blog', 'title' => t('blogs'));
......@@ -237,8 +237,6 @@ function blog_view($node, $teaser = FALSE, $page = FALSE) {
}
// prepare the node content
$node = blog_content($node, $teaser);
// print the node
return theme('node', $node, $teaser, $page);
}
/**
......
This diff is collapsed.
This diff is collapsed.
......@@ -207,7 +207,7 @@ function forum_content($node, $teaser = FALSE) {
/**
* Implementation of hook_view().
*/
function forum_view($node, $teaser = FALSE, $page = FALSE) {
function forum_view(&$node, $teaser = FALSE, $page = FALSE) {
if ($page) {
$vocabulary = taxonomy_get_vocabulary(variable_get('forum_nav_vocabulary', ''));
......@@ -224,7 +224,7 @@ function forum_view($node, $teaser = FALSE, $page = FALSE) {
menu_set_location($breadcrumb);
}
return theme('node', forum_content($node, $teaser), $teaser, $page);
$node = forum_content($node, $teaser);
}
/**
......
......@@ -207,7 +207,7 @@ function forum_content($node, $teaser = FALSE) {
/**
* Implementation of hook_view().
*/
function forum_view($node, $teaser = FALSE, $page = FALSE) {
function forum_view(&$node, $teaser = FALSE, $page = FALSE) {
if ($page) {
$vocabulary = taxonomy_get_vocabulary(variable_get('forum_nav_vocabulary', ''));
......@@ -224,7 +224,7 @@ function forum_view($node, $teaser = FALSE, $page = FALSE) {
menu_set_location($breadcrumb);
}
return theme('node', forum_content($node, $teaser), $teaser, $page);
$node = forum_content($node, $teaser);
}
/**
......
......@@ -490,17 +490,18 @@ function node_view($node, $teaser = FALSE, $page = FALSE) {
// TODO: this strips legitimate uses of '<!--break-->' also.
$node->body = str_replace('<!--break-->', '', $node->body);
// Allow modules to change $node->body before viewing.
node_invoke_nodeapi($node, 'view', $teaser, $page);
// The 'view' hook can be implemented to overwrite the default function
// to display nodes.
if (node_hook($node, 'view')) {
return node_invoke($node, 'view', $teaser, $page);
node_invoke($node, 'view', $teaser, $page);
}
else {
return theme('node', node_prepare($node, $teaser), $teaser, $page);
$node = node_prepare($node, $teaser);
}
// Allow modules to change $node->body before viewing.
node_invoke_nodeapi($node, 'view', $teaser, $page);
return theme('node', $node, $teaser, $page);
}
/**
......
......@@ -490,17 +490,18 @@ function node_view($node, $teaser = FALSE, $page = FALSE) {
// TODO: this strips legitimate uses of '<!--break-->' also.
$node->body = str_replace('<!--break-->', '', $node->body);
// Allow modules to change $node->body before viewing.
node_invoke_nodeapi($node, 'view', $teaser, $page);
// The 'view' hook can be implemented to overwrite the default function
// to display nodes.
if (node_hook($node, 'view')) {
return node_invoke($node, 'view', $teaser, $page);
node_invoke($node, 'view', $teaser, $page);
}
else {
return theme('node', node_prepare($node, $teaser), $teaser, $page);
$node = node_prepare($node, $teaser);
}
// Allow modules to change $node->body before viewing.
node_invoke_nodeapi($node, 'view', $teaser, $page);
return theme('node', $node, $teaser, $page);
}
/**
......
......@@ -121,11 +121,9 @@ function page_content($node, $teaser = FALSE) {
/**
* Implementation of hook_view().
*/
function page_view($node, $teaser = FALSE, $page = FALSE) {
function page_view(&$node, $teaser = FALSE, $page = FALSE) {
// prepare the node content
$node = page_content($node, $teaser);
// print the node
return theme('node', $node, $teaser, $page);
}
/**
......
......@@ -121,11 +121,9 @@ function page_content($node, $teaser = FALSE) {
/**
* Implementation of hook_view().
*/
function page_view($node, $teaser = FALSE, $page = FALSE) {
function page_view(&$node, $teaser = FALSE, $page = FALSE) {
// prepare the node content
$node = page_content($node, $teaser);
// print the node
return theme('node', $node, $teaser, $page);
}
/**
......
......@@ -413,7 +413,7 @@ function poll_vote(&$node) {
* An extra parameter that adapts the hook to display a block-ready
* rendering of the poll.
*/
function poll_view(&$node, $main = 0, $page = 0, $block = 0) {
function poll_view(&$node, $teaser = FALSE, $page = FALSE, $block = FALSE) {
global $user;
$output = '';
......@@ -439,11 +439,6 @@ function poll_view(&$node, $main = 0, $page = 0, $block = 0) {
}
$node->body = $node->teaser = $output;
// We also use poll_view() for the side-block
if (!$block) {
return theme('node', $node, $main, $page);
}
}
/**
......
......@@ -413,7 +413,7 @@ function poll_vote(&$node) {
* An extra parameter that adapts the hook to display a block-ready
* rendering of the poll.
*/
function poll_view(&$node, $main = 0, $page = 0, $block = 0) {
function poll_view(&$node, $teaser = FALSE, $page = FALSE, $block = FALSE) {
global $user;
$output = '';
......@@ -439,11 +439,6 @@ function poll_view(&$node, $main = 0, $page = 0, $block = 0) {
}
$node->body = $node->teaser = $output;
// We also use poll_view() for the side-block
if (!$block) {
return theme('node', $node, $main, $page);
}
}
/**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment