Skip to content

Latest commit

 

History

History
124 lines (117 loc) · 4.81 KB

09-node.md

File metadata and controls

124 lines (117 loc) · 4.81 KB

Nodes

Note: this chapter is not yet complete!

Nodes are Drupal's most basic content unit. Traditionally in Drupal every type of content like a page or blog post is a node, although in Drupal 7 it is not strictly necessary to use nodes when something like a Views Page or an Entity record might be more suitable. Modules can define their own node types as well.

Here are the default properties of Drupal 7 node objects from the official documentation. Generally all these properties are available in the theme layer when working with node displays:

$node->nid Node ID.
$node->vid The revision ID of the current version of this node.
$node->type Type of node (e.g. book, page, forum), which is also the entity bundle.
$node->language The default language for this node.
$node->title Page (or, more accurately, node) title.
$node->uid User ID of node creator.
$node->status unpublished/published (NODE_NOT_PUBLISHED | NODE_PUBLISHED).
$node->created UNIX timestamp of node creation date.
$node->changed UNIX timestamp of last time node was changed.
$node->comment Whether comments are allowed on this node (COMMENT_NODE_HIDDEN | COMMENT_NODE_CLOSED | COMMENT_NODE_OPEN)
$node->promote Promoted to front page (NODE_NOT_PROMOTED | NODE_PROMOTED).
$node->sticky Sticky (NODE_NOT_STICKY | NODE_STICKY).
$node->tnid The node ID of the translation source (or parent, if node is a translation).
$node->translate Does the translation need to be updated (0|1)?
$node->revision_uid The user ID of the user who created the current revision.
$node->body Array. Body content of node. Long text field with summary.
Note: Don't assume that this field will exist, as it is possible to remove it via Manage Fields on each content type. Similarly, modules that define a custom node content type may not even attach a body in the first place.
$node->log Message left by the creator of this revision, explaining the changes.
$node->revision_timestamp Unix timestamp showing when current revision was created.
$node->name Username of node creator.
$node->picture User avatar of the node creator.
$node->cid CID of last comment?
$node->last_comment_timestamp Timestamp of last comment (Unix Epoch C).
$node->last_comment_name Name of last comment author
$node->last_comment_uid UID of last comment author.
$node->comment_count Number of comments made on node.
$node->data Serialized string of data associated with the node.
$node->rdf_mapping W3C standard to describe structured data. See http://api.drupal.org/api/drupal/modules!rdf!rdf.module/group/rdf/7

Adding properties to nodes

To create a new property on a node programmatically, the Entity API module can be very helpful. The hook_entity_property_info hook lets you set up the metadata properties. The entity_metadata_node_entity_property_info function implements hook_entity_property_info() on top of the node module, for default node property definitions.

You can find more documentation in the Entity API handbooks. Also check the README and the provided API docs in entity.api.php.