This example demonstrates how to programmatically define a content type.

This is an example outlining how a module can define a new content type. The example content type allows users to specify multiple colors, a quantity, and an image. It could be used as some kind of rudimentary inventory-tracking system.

The basic pattern for defining a content type is to tell Backdrop about the node fields and view modes. Backdrop will then take over and manage the storage for this content type.

Remember that most content types do not require any custom code, as they are usually created using the Backdrop user interface.

At absolute minimum, in order to provide a content type, you have to implement hook_form(). The Node module can take care of the rest, if you want.

Next, since we want to add fields to our content type, we implement hook_node_type_insert(), which gives us a chance to modify recently-created content types.

Backdrop is able to handle deletion of our content, including dependencies based on re-use of our field instances, so we don't have to manage any of it.

Consult Field API.

See also


Parent topics


modules/examples/node_type_example/node_type_example.module, line 9
Hook implementations for the Node Type Example module.


Namesort descending Location Description
node_type_example_entity_info_alter modules/examples/node_type_example/node_type_example.module Implements hook_entity_info_alter().
node_type_example_field_formatter_info modules/examples/node_type_example/node_type_example.module Implements hook_field_formatter_info().
node_type_example_field_formatter_view modules/examples/node_type_example/node_type_example.module Implements hook_field_formatter_view().
node_type_example_form modules/examples/node_type_example/node_type_example.module Implements hook_form().
node_type_example_menu modules/examples/node_type_example/node_type_example.module Implements hook_menu().
node_type_example_node_type_insert modules/examples/node_type_example/node_type_example.module Implements hook_node_type_insert().
node_type_example_page modules/examples/node_type_example/node_type_example.module Callback that builds our content.
node_type_example_theme modules/examples/node_type_example/node_type_example.module Implements hook_theme().
theme_node_type_example_color modules/examples/node_type_example/node_type_example.module A custom theme function.
_node_type_example_installed_fields modules/examples/node_type_example/node_type_example.module Defines the fields for our content type.
_node_type_example_installed_instances modules/examples/node_type_example/node_type_example.module Defines the field instances for our content type.


Namesort descending Location Description
NodeTypeExampleTest modules/examples/node_type_example/tests/node_type_example.test Functionality tests for The Node Type Example module.