Blogs

Jun 15 2009

Disallow node discovery by ID

Recently I wondered if viewing a node via its internal path could be disallowed, making it accessible using a path alias only. With hook_menu_alter(), a router item's page callback can be changed to our own function that will check if the requested path is internal or not.

<?php
function hidenid_menu_alter(&$items) {
 
$items['node']['page callback'] = 'hidenid_check';
 
$items['node/%node']['page callback'] = 'hidenid_check';
 
$items['node/%node/view']['page callback'] = 'hidenid_check';
}

function hidenid_check($node = NULL, $cid = NULL) {
 
$path = $_REQUEST['q'];
 
  if (
strpos($path, 'node') === 0) {
   
drupal_not_found();
    return;
  }
  return
node_page_view($node, $cid);
}
?>

••• (#)
Apr 7 2009

Multi-step Forms in Drupal 6 using variable functions

I recently had to write a multi-step form in Drupal 6. Of course, I turned to documentation to see how others are doing it. Pro Drupal Development offers the basics, so do the 5 to 6 upgrade notes, and others. I felt that many approaches suffered from design flaws that made the code cumbersome to manage beyond a couple steps. I set out to develop a multi-step form method with the following goals:

  • One form builder with nested conditional statements is difficult to manage, each step should be its own form array function
  • Steps shouldn't be numbered, e.g. to move to the next step don't $form_state['storage']['step']++
  • Each step should be able to have its own validate and submit handlers
  • Steps should be form alterable
••• (#)