Drupal node module skeleton

Drupal node module skeleton

Recipe for creating a node module skeleton: 1. Create three files using the code snippets at the bottom of this post
  • foo.info
  • foo.module
  • foo.theme
Note: replace foo with your module name. If this is for a specific project, use project codes in the format [pc][nodetype] 2. do the following search and replace on all three files "[pc]foo" -> [pc][nodetype] "foo" -> [nodetype] foo.info code: ; $Id $ name = "Foo" description = "Foo posts." package = dependencies = foo.module code: array( 'name' => t('Foo'), // Human readable name. Required. 'module' => 'foo', // Machine readable name. (alphanueric, '_' only) Required. 'description' => t('This is foo'), // Required. 'has_title' => TRUE, 'title_label' => t('Title'), 'has_body' => TRUE, 'body_label' => t('Body'), 'min_word_count' => 0, 'locked' => TRUE ) ); } /** * Implementation of hook_menu(). */ function foo_menu($may_cache) { $items = array(); // Do not cache this menu item during the development of this module. if (!$may_cache) { } else { } return $items; } /** * Implementation of hook_perm(). */ function foo_perm() { return array('create foo', 'edit own foo', 'edit foo'); } /** * Implementation of hook_access(). */ function foo_access($op, $node) { global $user; if ($op == 'create') { return (user_access('create foo')); } if ($op == 'update' || $op == 'delete') { return (user_access('edit foo') || (user_access('edit own foo') && ($user->uid == $node->uid))); } } /** * Implementation of hook_form(). */ function foo_form($node) { $type = node_get_types('type', $node); if ($type->has_title) { $form['title'] = array( '#type' => 'textfield', '#title' => check_plain($type->title_label), '#default_value' => $node->title, '#size' => 128, '#maxlength' => 128, '#weight' => -5, ); } if ($type->has_body) { $form['body_filter']['body'] = array( '#type' => 'textarea', '#title' => check_plain($type->body_label), '#default_value' => $node->body, '#weight' => 0, '#rows' => 10, ); } $form['body_filter']['filter'] = filter_form($node->format); $form['body_filter']['#weight'] = -4; return $form; } /** * Implementation of hook_validate(). */ function foo_validate($node) { } /** * Implementation of hook_insert(). */ function foo_insert($node) { } /** * Implementation of hook_update(). */ function foo_update($node) { } /** * Implementation of hook_delete(). */ function foo_delete(&$node) { } /** * Implementation of hook_load(). */ function foo_load($node) { } /** * Implementation of hook_view(). */ function foo_view($node, $teaser = FALSE, $page = FALSE) { if (!$teaser) { // Use Drupal's default node view. $node = node_prepare($node, $teaser); } if ($teaser) { // Use Drupal's default node view. $node = node_prepare($node, $teaser); } return $node; } foo.theme code:

Related Posts

How to Add Drag and Drop Blocks to any Node on your Drupal Website

Randall Knutson
Read more

Drupal node publishing options

Tom McCracken
Read more

Drupal 8 Module Development, Part 1: Getting Started

Ian Whitcomb
Read more

Drupal Importing Nodes with the Feeds Module

Chris Sloan
Read more

Drupal 8 Module Development, Part 2: Forms

Ian Whitcomb
Read more

Drupal 8 Module Development, Part 3: Plugins

Ian Whitcomb
Read more