node_example.module

Version 1.7 (checked in on 2010/10/15 at 14:52:26 by rfay)

This is an example outlining how a module can be used to define a new node type. In Drupal 7 we move most of what was once needed in this file to the node_example.install file so that it can be managed efficiently.

Our example node type will allow users to specify multiple "colors", a "quantity" and an "image" for their nodes; some kind of rudimentary inventory-tracking system, perhaps?

In previous versions of Drupal, "teaser" and "page" were node view modes. In Drupal 7 we can define custom view modes to let the node know how it should return it's data. This module declares a custom view mode called "example_node_list".

We no longer need an extra database table to store this content type's information.

Most node types that provide fields do not require any custom code for the fields, as the fields system provides storage and access.

See Field API Tutorial

See Field API Handbook Page

See Field API documentation

See field_example.install

Remember that most node types do not require any custom code, as one simply creates them using the fields UI.

Functions & methods

NameDescription
node_example_entity_info_alterImplements hook_entity_info_alter().
node_example_field_formatter_infoImplements hook_field_formatter_info().
node_example_field_formatter_viewImplements hook_field_formatter_view().
node_example_helpImplements hook_help().
node_example_menuImplements hook_menu().
node_example_pageCustom callback that builds our content and returns it to the browser.
node_example_themeImplements hook_theme().
theme_example_node_colorA custom theme function.