Heine

  • home
  • drupal
  • drupal core commits
  • about
Home

Example scaffolding

Before we dive into the details of the Forms API, we need a little scaffolding code to enable you to test the examples on a site. Here we map the URL example/page to the function call example_page(). We'll later fill this function with relevant code.

function example_menu($may_cache) {
  if ($may_cache) {
    $items = array();
    $items[] = array(
      'path' => 'example/page',
      'title' => 'Example',
      'callback' => 'example_page',
      'access' => user_access('access example'),
      'type' => MENU_CALLBACK,
    );
    return $items;
  }
}

function example_perm() {
  return array('access example');
}

/**
  * This function will be called upon a visit to example/page.
  */

function example_page() {
 
}

The example implements the following hooks:

hook_menu
Maps URLs to callback functions in addition to providing a way to define actual entries in the navigation menu.
hook_perm
Supplies permissions that can be assigned on the admin/users/access page and checked with user_access().

To use the example code on your site, you can save it in sites/all/modules/example/example.module together with example.info:

name = Example
description = Toy with FAPI examples.

Average: 3 (10 votes)
‹ Drupal Forms API up FAPI stages ›
  • Printer-friendly version

Recent posts

  • Planet Drupal past and current
  • Help! - Cannot access a global variable.
  • Why is my module's update hook not listed on update.php's selection form?
  • How do I add a class to a link generated with l()
  • ZeroDayScan - Full path disclosure bug in Drupal 6.16 (0day)
more

Security reviews

  • Afraid custom code makes your site vulnerable?
  • You don't really trust that module you just downloaded from Drupal.org?

Sleep better after a security review.

Tags

Captcha CSRF Drupal embed Input Format modx OpenID Performance Planet Drupal rants Security Varnish
more tags
  • home
  • drupal
  • drupal core commits
  • about

Copyright © 2010 by Heine Deelstra. All rights reserved.