hooks

Drupal: Expose a Custom Field to Views2

Disclaimer: Views2 Advanced Help contains a more detailed and comprehensive documentation on the same subject. However, that also means that you have to actually comprehend more :) This is just a quick sample code of one usage of the hook_views_data() to expose custom fields from a custom table to Views2. If you need more advanced functionality, do refer to Views2 documentation.

Let's say we are building a small job posting board and, for whatever reason, decided to store all resume-related extra fields in a table called "resume", instead of using CCK. Now we need to expose those fields to Views, to use all the beauty and flexibility of the automated query generation provided by Views.

Let's write a custom module called resume (or add it to an existing module).

The very first thing you need to do when you implement Views hooks is to tell Views that you are doing so and (optionally) - where your inc file will rely that holds all views hook implementation routines. We do that using hook_views_api(). Assuming your module is called "resume" and that you want to put views hook implementation file in the "views" subfolder:

function resume_views_api() {
  return array(
    'api' => 2,
    'path' => 
   drupal_get_path('module', 'resume') . '/views',
  );
}

If you omit the "path" argument, you will have to create the modulename.views.inc file in the root folder of your module (or "includes" subfolder). If you do indicate path - you create it on that path.

Let's create resume.views.inc file (under the "views" fubfolder of the resume module's folder, in our case) and enter following code in it:

Extreme Form Handling in Drupal

Via: AgileApproach Blog

Drupal Form-Handling support goes far beyond just the documented part of so-called Forms API. You can do pretty much anything with forms in Drupal and you can use/display the forms anywhere.

Here is an example. Let's assume we want to construct a custom node type with custom fields, using CCK. Then we want to display this form into some non-standard page. To further complicate things, let's assume we also want custom verification and processing routines.

And last but not least - we want to use full power of Drupal and write a minimal amount of code. Following is a snippet demonstrating key points to achieving this task (thorough understanding of Drupal is required):

Syndicate content