In Zeile 6, registriere ich hier einen Menü-Pfad mit einer sog. Wildcard, also einem Platzhalter.

Das bedeutet in diesem Fall, dass während der Pfad-Anteil example/ fix ist, dass der zweite Pfad-Anteil %node_type_nid, wie hoffentlich schon durch seine Benennung deutlich wird, Node-ID’s (nids) von Node-Typ example enthalten soll.

<?php
/**
 * Implements hook_menu().
 */
function example_menu() {
  $items = array();
  $items['example/%node_type_example_nid'] = array(
    'title' => 'Example page title',
    'description' => 'Example page description',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('example_form', 1),
    'access callback' => TRUE,
  );
  return $items;
}
  • 404 bei Aufruf von example/123?
  • Wie bekomme ich es hin, dass der Pfad nur in Verbindung von Node-ID's vom Typ example valide ist?
  • ...vielleicht noch zusätzliche Validierungen?

Auto-Loader Wildcards

Registered paths may also contain special "auto-loader" wildcard components in the form of '%mymodule_abc', where the '%' part means that this path component is a wildcard, and the 'mymodule_abc' part defines the prefix for a load function, which here would be named mymodule_abc_load().http://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_menu/7

Hier die special auto-loader Funktion, benannt nach dem Namen der Wildcard als Prefix, node_type_example_nid + _load.

<?php
function node_type_example_nid_load($nid) {
  $node = node_load($nid);
  if ($node) {
    if ($node->type == 'example_node_type') {
      global $user;
      // Only node author/owner might access.
      if ($user->uid == $node->uid) {
        return $nid;
      }
      else {
        return FALSE;
      }
    }
    else {
      return FALSE;
    }
  }
  else {
    return FALSE;
  }
}