Community Documentation

hook_view

5 node.php hook_view($node, $teaser = FALSE, $page = FALSE)
6 node.php hook_view($node, $teaser = FALSE, $page = FALSE)
7 node.api.php hook_view($node, $view_mode)
8 node.api.php hook_view($node, $view_mode)

Display a node.

This is a hook used by node modules. It allows a module to define a custom method of displaying its nodes, usually by displaying extra information particular to that node type.

Parameters

$node: The node to be displayed.

$teaser: Whether we are to generate a "teaser" or summary of the node, rather than display the whole thing.

$page: Whether the node is being displayed as a standalone page. If this is TRUE, the node title should not be displayed, as it will be printed automatically by the theme system. Also, the module may choose to alter the default breadcrumb trail in this case.

Return value

$node. The passed $node parameter should be modified as necessary and returned so it can be properly presented. Nodes are prepared for display by assembling a structured array in $node->content, rather than directly manipulating $node->body and $node->teaser. The format of this array is the same used by the Forms API. As with FormAPI arrays, the #weight property can be used to control the relative positions of added elements. If for some reason you need to change the body or teaser returned by node_prepare(), you can modify $node->content['body']['#value']. Note that this will be the un-rendered content. To modify the rendered output, see hook_nodeapi($op = 'alter').

For a detailed usage example, see node_example.module.

Related topics

▾ 30 functions implement hook_view()

aggregator_admin_overview in modules/aggregator/aggregator.admin.inc
Menu callback; displays the aggregator administration page.
aggregator_view in modules/aggregator/aggregator.admin.inc
Displays the aggregator administration page.
blog_view in modules/blog/blog.module
Implementation of hook_view().
book_admin_overview in modules/book/book.admin.inc
Returns an administrative overview of all books.
comment_admin_overview in modules/comment/comment.admin.inc
Form builder; Builds the comment overview form for the admin.
comment_form_add_preview in modules/comment/comment.module
Form builder; Generate and validate a comment preview form.
dblog_overview in modules/dblog/dblog.admin.inc
Menu callback; displays a listing of log messages.
filter_admin_overview in modules/filter/filter.admin.inc
Menu callback; Displays a list of all input formats and which one is the default.
forum_overview in modules/forum/forum.admin.inc
Returns an overview list of existing forums and containers
Language overview functionality in includes/locale.inc
NODE_BUILD_PREVIEW in modules/node/node.module
node_form_build_preview in modules/node/node.pages.inc
node_page_view in modules/node/node.module
Menu callback; view a single node.
node_preview in modules/node/node.pages.inc
Generate a node preview.
node_revision_overview in modules/node/node.pages.inc
Generate an overview table of older revisions of a node.
node_view in modules/node/node.module
Generate a display of the given node.
path_admin_overview in modules/path/path.admin.inc
Return a listing of all defined URL aliases. When filter key passed, perform a standard search on the given key, and return the list of matching URL aliases.
poll_view in modules/poll/poll.module
Implementation of hook_view().
profile_admin_overview in modules/profile/profile.admin.inc
Form builder to display a listing of all editable profile fields.
search_view in modules/search/search.pages.inc
Menu callback; presents the search form and/or search results.
system_logging_overview in modules/system/system.admin.inc
Menu callback; Menu page for the various logging options.
system_settings_overview in modules/system/system.admin.inc
Menu callback; displays a module's settings page.
theme_comment_admin_overview in modules/comment/comment.admin.inc
Theme the comment admin form.
theme_comment_view in modules/comment/comment.module
Themes a single comment and related items.
theme_filter_admin_overview in modules/filter/filter.admin.inc
Theme the admin overview form.
theme_node_preview in modules/node/node.pages.inc
Display a node preview for display during node creation and editing.
theme_profile_admin_overview in modules/profile/profile.admin.inc
Theme the profile field overview into a drag and drop enabled table.
Translation overview screen. in includes/locale.inc
translation_node_overview in modules/translation/translation.pages.inc
Overview page for a node's translations.
user_view in modules/user/user.pages.inc
Menu callback; Displays a user or user profile page.

File

developer/hooks/node.php, line 410
These hooks are defined by node modules, modules that define a new kind of node.

Code

<?php
function hook_view($node, $teaser = FALSE, $page = FALSE) {
  if ($page) {
    $breadcrumb = array();
    $breadcrumb[] = l(t('Home'), NULL);
    $breadcrumb[] = l(t('Example'), 'example');
    $breadcrumb[] = l($node->field1, 'example/' . $node->field1);
    drupal_set_breadcrumb($breadcrumb);
  }

  $node = node_prepare($node, $teaser);
  $node->content['myfield'] = array(
    '#value' => theme('mymodule_myfield', $node->myfield), 
    '#weight' => 1,
  );

  return $node;
}
?>

Comments

Just took me 2 hours to find

Just took me 2 hours to find out this function will not work on non-node modules.
Use hook_nodeapi() "view" instead.

What does non-node modules mean?

Curious what "non-node modules" means? Perhaps modules that create content types? Do we need to register some kind of function to get this hook enabled?

We need to user hook_view rather than hook_nodeapi for conflict reasons.

Thanks

Thanks man, this same me a lot of time, I am glad I see you post, it seems than any of the hook_nodes works for non-node modules, It didn't work for the hook_insert, hook_update, hook_view, hook_delete

Login or register to post comments