Drupals node building mechanism

(This walkthrough done on pre-4.5 CVS code in August 2004.) The node_page controller checks for a _POST 'op' entry and, failing that, sets op to arg(1) which in this case is the '1' in node 1. A numeric op is set to arg(2) if arg(2) exists, but in this case it doesn't ('1' is the end of the URL, remember ) so the op is hardcoded to 'view'. Thus, we succeed in the 'view' case of the switch statement, and are shunted over to node_load(). The function node_load() takes two arguments, conditions...

What you need

O means to download upload files to your modules directory O a text editor O a little php knowledge is helpful, but not required o a technical name for your node type (16 character limit) - no spaces, numbers or punctuation unless you know what you're doing (don't use the name of a module you already have) O a user-frieldly name for your node type (and a plural version of this name) (this is how your node type will appear in most places on your site) - spaces and numbers are ok but again no...

Converting Xmlrpc using modules

The first Drupal versions to use the new library are 4.5.5, 4.6.3 and 4.7. If you have a custom written Drupal module for an older version, then the following applies. return array 'foaf.getUrl' gt array 'function' gt 'foaf_get_url' gt return array 'foaf.getUrl' gt 'foaf_get_url' gt Now let's see the handler function itself. It's parameters are regular PHP variables now, there is nothing to process. So now you can write things like function username, password instead of doing parameter...

Win Merge

While these programs do a nice job in showing file differences visually, side by side, non of them as i can tell allows to actually save the difference in unified format most allow to save a standard diff, though - update TortoiseCVS lets you save patches. It does unified format by default. See its Make Patch option. Note that this 'Make Patch' option can make recursive patches when applied to directories. You cannot specify the -u in the External diff preferences eg diff -u as this will...

Theme engine integration

Your site's theme may have special content and features that do not exist in Drupal themes. This section will explain how you can use your own themes using Drupal's theme engines. If all you need to achieve a common look and feel, you do not need to modify a theme engine, you can simply create a new template based on your site's design elements. Drupal currently has the following theme engines Xtemplate, PHPTemplate, Smarty and Plain PHP. You can read an in-depth explanation of these template...

Text output

Drupal's text output was audited and several escaping bugs were found. For more info, see the check_plain patch. You need to pay attention that all user-submitted plain-text in your module is escaped using check_plain when you output it into HTML. No escaping should be done on data that is going into the database only escape when outputting to HTML. Check_plain replaces drupal_specialchars and check_form , so if you are using any of those two, you should use check_plain instead. You should also...

Taxonomy API change

In order to provide more meaningful messages to the user, now you can provide your own messages when using the taxonomy APIs to create or modify terms and vocabularies. The taxonomy_save_vocabulary and taxonomy_save_term functions now return a status message which can be either SAVED_NEW, SAVED_UPDATED or SAVED_DELETED. The function will return NULL when there was an error. Also note that you must call these with an edit array parameter which will be modified, and will include the 'vid' key....

Node definition changes

In 4.6, you had hook_node_name and hook_node_types. Now you must implement hook_node_info if you want to create a module which defines node type s . The implementation of the hook_node_info needs to return array type1 gt array 'name' gt name1, 'base' gt base1 , type2 gt array 'name' gt name2, 'base' gt base2 where type is the node type, name is the human readable name of the type and base is For example, the story module's node_info hook looks like this return array 'story' gt array 'name' gt t...

Drupals Javascript tools

Drupal's javascript toolkit has three basic components The javascript file drupal.js contains methods for implementing Javascript solutions, including AJAX see below . Specific Drupal functions in PHP help Javascript developers. These include drupal_add_j s , used for adding a js file to a page drupal_call_j s , used to generate a javascript call and drupal_to_js , used to translate data from Drupal PHP to Javascript objects. As well as the generic tools in drupal.js and the PHP Javascript...

Write EALL compliant code Introductionary notice

This document is a very recent addition to the coding guidelines, and is still subject to discussion among developers. Do NOT post comments on this page yet. One issue will be created for each point introduced here. Those issues will be used for discussion and patch submission. I'll keep updating this page as the discussion progresses. When a consensus has been reached on each point, this introduction will be deleted. Eventually, when everything has been patched up, I'll delete the mention...

How do you use the validation arguments

valid gt 'integer' , validation arguments gt array 1, 13 This would map to valid_integer form 'element' , 1, 13 where 1, 13 could be min max allowed values. If you have multiple validation functions, use valid gt array 'integer', 'uid' , validation arguments array array 1, 13 , array 'anonymous' which would map to valid_integer form 'element' , 1, 13 and valid_uid form 'element' , 'anonymous' where the second parameter could be role, for instance, so you could see if it's a valid uid in a...

Session handler issues

Managing your session issues will greatly depend on how your application handles sessions, But the Drupal side of things is straight forward. The session.inc file is included in the bootstrap.inc file. If you decide to exclusively use your application's session handler, you can simply comment out that line from bootstrap.inc. Or you may decide to allow both to do different parts, where your application session handles authentication, and let Drupal sessions handle the rest of Drupal functions....

Database table prefix

On 2003 Jul 10, Dries committed Slavica's table prefix patch which allows for a configurable prefix to each drupal mysql table to easily share one database for multiply applications on server with only one database allowed. This patch requires all table names in SQL-queries to be enclosed in curly brackets , eg. - db_query DELETE FROM book WHERE nid d, node- gt nid db_query DELETE FROM book WHERE nid d, node- gt nid so that the table prefix can be dynamically prepended to the table name. See...

Prebuilt autocomplete functions

Two autocomplete functions ship with the Drupal core. Each is referenced by an autocomplete_path--the uri to which autocomplete requests are sent. Use this function to load matching user names. Autocomplete path user autocomplete. Use this function to load matching taxonomy terms from a given vocabulary. Autocomplete path taxonomy automplete. If one of these matches your needs, then all you need to do is include the special autocomplete_path selector in a form field. Here's an example for user...

Hookonload replaced by addLoad Event

If you need to add Javascript onLoad events from your modules you now need to use the Drupal custom Javascript function addLoadEvent func . This was done to allow for new Javacript functions in the core. return array 'my_javascript_function ' TO BE USED INSIDE YOUR FUNCTION THAT NEEDS TO LOAD A JAVASCRIPT FUNCTION

Modifying checkboxes to display in multiple columns

This tip will show you how to modify the checkboxes element type so that checkboxes display in multiple columns instead of one single column. This is particulary useful for modules that would have users select from a very long list of choices. This tip will help you present the checkboxes in a more compact form, making your site more user friendly. Disclaimer This document shares how I solved this particular problem and doesn't claim to be anything more. There may be other ways of accomplishing...

Tutorial Creating new Javascript widgets

If you want to implement functionality not already available, you'll create a new Javascript file and then write PHP calls that add to the page what's needed for the Javascript to work. So, to come up with a simple if fairly useless example, say we want to write a module that allows users to click on specific words and get a message with further information. Here's how we might do it. Use CSS class selectors to identify the elements to add the Javascript to. You might be familiar with the...