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 the Field API documentation.
See also
Parent topics
File
- modules/
examples/ node_type_example/ node_type_example.module, line 9 - Hook implementations for the Node Type Example module.
Functions
Classes
Name | Location | Description |
---|---|---|
NodeTypeExampleTest |
modules/ |
Functionality tests for The Node Type Example module. |