background preloader

Module Development

Facebook Twitter

Examples for Developers. Follow the Examples project on Twitter: The Examples for Developers project has a Gittip team page. You can contribute financially to the project: Code Examples For Drupal The Examples for Developers project aims to provide high-quality, well-documented API examples for a broad range of Drupal core functionality. The Examples project contains many modules which hopefully illustrate best practices for implementing various Drupal APIs. These modules can be enabled individually, and will typically add menu items to your site, which should guide you through their features. You can then look through the code to see what they are doing. Developers can learn how to use a particular API quickly by experimenting with the examples, and adapt them for their own use. Note also that these modules demonstrate internals for Drupal development in PHP (and some JavaScript).

How To Use These Modules As Modules API.Drupal.Org Adapt The Code. Modifying Forms in Drupal 5 and 6. Drupal has a lot of forms to fill out and not all of them may be just the way you want or need them to be. Modifying forms is a topic that is often met with groans but once you understand the two methods to accomplish the task and the basic, underlying concepts, it really isn't that hard to do at all. You'll be a form-modifying, input-customizing wiz in no time. This article will briefly discuss what's going on and then mainly focus on showing working examples for both methods in Drupal 5 and 6. You should be comfortable creating a new function, looking at arrays and a having at least a passing understanding of the Forms API is real handy. Also note that in the examples below I have them wrapped in php tags but you should not include those if you copy/paste.

That is just so it looks nice and clear for the article. Deciding to make the change in the theme or a module So there are two methods for altering form output in Drupal, one at the theme layer and the other through a custom module. AHAH in Drupal: may it one day live up to its acronym | katbailey.net. With a name like AHAH, one might expect positive experiences in one's dealings with it. But often a name like "AGAH! " would seem more appropriate (Asynchronous Groaning and Headbashing?). There's no doubt about it - AHAH in Drupal is hard. I'm referring here to the trick of dynamically changing elements on a form or adding new ones, as is done on the poll creation form in core. It was next to impossible in Drupal 5, promises to be fairly straight-forward in Drupal 7, but has many people tearing their hair out in Drupal 6.

In a nutshell, the reason it's hard is that Drupal needs to ensure that all form submissions are legal and secure, so it won't simply accept submissions from elements it didn't know about when it first rendered the form. A few months ago, I wrote a blog post entitled The dual aspect of Drupal forms and what this means for your AHAH callback, after having been enlightened by chx as to Form API / AHAH best practices. <? // ... element definitions <? <? Here's the button code: Applying patches. This information deals with applying patches without git.

For information on using git to apply patches, please see the git patch contributor guide. For more generic information about patches, please see the Patch section of the Getting Involved Guide. Applying patches, modifying files according to instructions in the patch file, is the domain of patch programs. There are many different programs with this functionality, some stand-alone (patch), some integrated in IDEs (Eclipse, XCode). Warning: Patching is something that should never be done on your production site unless you first have a complete backup of your site, and you have tested that backup: First.

This page only deals with some basic principles using the command line utility patch. Provided that the patch was made relative to the root directory of the concerned project, navigate to the that directory (using cd). If you are using Git: git apply --index path/file.patch patch -p1 < path/file.patch patch < file.patch. Call a function from another module.