Community Documentation

Drupal templates for NetBeans

Last updated May 10, 2013. Created by kalman.hosszu on January 10, 2011.
Edited by decibel.places, znurgl. Log in to edit this page.

Installation

  1. Create a zip file of the content in the src directory (do not zip the src directory itself; zip up the content inside the directory).
  2. Go to NetBeans > Preferences > Editor > Code Templates > Import
  3. Browse the created zip file
  4. Select Editor > Code Templates
  5. Press OK

Usage

On the NetBeans Templates project page, you can download a file which you can easily import into NetBeans in Preferences > Editor > Code Templates..

NetBeans templates

With this template file all of the Drupal hooks can be generated with their base structure and rules.

Using template expressions: type keyword and press TAB. The code template expands.

For example in D6 version the "h_block" word generates the following lines:

<?php
/**
* Implementation of hook_block().
*
* @param $op What kind of information to retrieve about the block. Possible values: list, configure, save, view.
* @param $delta Which block to return.
* @param $edit Data from a configuration form, if submitted.
*/
function ${mymodule}_block($op = 'list', $delta = 0, $edit = array()) {
  switch (
$op) {
    case
'list':
     
$blocks = array();

     
$blocks['${delta}'] = array(
       
'info' => t('${info}'),
      );

      return
$blocks;
      break;

    case
'view':
     
$blocks = array();

      switch (
$delta) {
        case
'${delta}':
         
$block['subject'] = t('${subject}');
          break;
      }

     
$block['content'] = ${mymodule}_block_content($delta);

      return
$block;
      break;
  }
}

/**
* Generate block contents.
*
* @param $delta The block id.
* @return The generated block content.
*/
function ${mymodule}_block_content($delta) {
  switch (
$delta) {
    case
'${delta}':
      return;
      break;
  }
}
?>

For "form":

<?php
/**
* Build ${module_form} form.
*
* @param array $form_state
* @return array The created form.
*/
function ${module_form}($form_state) {
 
$form = array();

  return
$form;
}
?>

and "form_validate":

<?php
/**
* Validate ${module_form} form
*
* @param $form form to validate
* @param $form_state A keyed array containing the current state of the form.
*/
function ${module_form}_validate($form, &$form_state) {
  if (${
form_field_test}) {
   
form_set_error('${form_field_id}', t('${form_field_error}'));
  }
}
?>

I created templates for info files too, so you can use "d6_minf" (for module info) and "tinf" (for template info) abbreviations.

; $Id$
name = ${modulename}
description = ${description}
package = Kalman Hosszu
version = VERSION
core = 6.x

dependencies[] = ${module}

; $Id$
name = ${mytheme}
description = ${description}
core = 6.x
version = VERSION
engine = phptemplate

stylesheets[all][] = ${style}.css

base theme = ${basetheme}

Or "d7_minf" generates:
name = ${modulename}
description = ${description}
package = Custom modules
version = VERSION
core = 7.x

dependencies[] = ${depmodule}

files[] = ${module}.module
files[] = ${module}.test

The annotation is customizable, currently it looks like this:

<?php
// $Id$
/**
* @file
* ${cursor}
*
*
* @author Kálmán Hosszu
*/

/* ====================== */
/* ==== DRUPAL HOOKS ==== */
/* ====================== */


/* ====================== */
/* == MODULE FUNCTIONS == */
/* ====================== */
?>

If you are a theme developer, and you find that not much of this is useful to you, i suggest using the Zen plugin , which generates html, using a simple logic:

div#page>div.logo+ul#navigation>li*5>a

this will be generated:
<?php
<div id="page">
    <
div class="logo"></div>
    <
ul id="navigation">
        <
li><a href=""></a></li>
        <
li><a href=""></a></li>
        <
li><a href=""></a></li>
        <
li><a href=""></a></li>
        <
li><a href=""></a></li>
    </
ul>
</
div>
?>

The Hungarian version of this page at here

In Netbeans 7 on Ubuntu use space instead of tab after the keyword to generate the code block template
Product Version: NetBeans IDE 7.0.1 (Build 20121011-unknown-revn)
Java: 1.6.0_27; OpenJDK 64-Bit Server VM 20.0-b12
System: Linux version 3.8.0-19-generic running on amd64; UTF-8; en_US (nb)

Comments

To use this, type the name of

To use this, type the name of the template and press tab. For example 'd7_form<tab>'. For the list of available templates, see Tools > Options > Editor > Code Templates.

"Download templates?" What is the code?

Please clarify a few things:
1) At the top of the page you state: "On the NetBeans Templates project page, you can download a file". Where is the "NetBeans Temples Project" page? I an running V7.0.1. Can one really download a Drupal plug-in via that page?

2) Are the code segments part of a template file? What do I do with them to use them?

Link

The "NetBeans Templates project" is a link to the project page where you can download the templates as a module. I suggest download the 7.x-1.x-dev version, because it contains all D6 hooks and many of the D7 hooks too. Check README file for installation details.
You can use templates:
d6/d7_hook_name

For example:
d6_nodeapi
Generates:

<?php
/**
* Implementation of hook_nodeapi().
*
* @param &$node The node the action is being performed on.
* @param $op What kind of action is being performed. Possible values: alter, delete, delete revision, insert, load,
*   prepare, prepare translation, print, rss item, search result, presave, update, update index, validate, view
* @param $a3
* @param $a4
*/
function mymodule_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
  switch (
$op) {
    case
'op':
      break;
  }
}
?>

Or:
d7_block_info
Generates:
<?php
/**
* Define all blocks provided by the module.
*
* @return
*   An associative array whose keys define the delta for each block and whose
*   values contain the block descriptions. Each block description is itself an
*   associative array, with the following key-value pairs:
*   - 'info': (required)
*   - 'cache': (optional)
*   - 'properties': (optional)
*   - 'weight': (optional)
*   - 'status': (optional)
*   - 'region': (optional)
*   - 'visibility': (optional)
*   - 'pages': (optional)
*/
function mymodule_block_info() {
 
$blocks = array();


 
$blocks['block'] = array(
   
'info' => t('info'),
   
'cache' => DRUPAL_NO_CACHE,
  );

  return
$blocks;
}
?>

Do you understand?

Kálmán Hosszu

Hi thanks for this template.

Hi thanks for this template. I am using 7.2 and I don't see this working. How do i test this?

Using parameters

Sorry, i'm a newbie with Netbeans.
How to define ${mymodule} and others parameters for different files?

netbeans 7.0.1 seems not work

netbeans 7.0.1 seems not work with drupal netbeans template

False

I'm using NB 7.0.1 and everythign works fine. If you find an issue, please open one in the project's issue queue!

Cheers

Kálmán Hosszu

FANTASTIC MODULE!

FANTASTIC MODULE!

Page status

No known problems

Log in to edit this page

About this page

Drupal version
Drupal 6.x, Drupal 7.x
Audience
Designers/themers, Programmers
Keywords
netbeans
Drupal’s online documentation is © 2000-2013 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License. Comments on documentation pages are used to improve content and then deleted.
nobody click here