User login

How does a Drupal module show...? Biblio listing

Situation is that we want autocomplete for referenced bibliography nodes to show authors, journal title, and year as well as article (node) title.

  1. Look at the module's implementation of hook_menu().

    If what you are looking is visible on your Drupal site, it is probably at a specific path. That means it is put there by the menu system, and Drupal modules can define their own menu items by implementing hook_menu.

    Using the example of the Biblio module, we take a look at biblio_menu to see where the "biblio" item is created. Biblio uses a $base variable instead of biblio/ in the menu directly, which seems unnecessary since the core path module can alias any path, but be aware of little gotchas like this.

    Alternative approach: Use the devel theme module (Drupal 6 only) in devel module to see what theming functions are calling what you want.

  2. Follow that to the 'page callback'. Check if 'file' is specified.

    Look in the menu item array for the path you seek ($items['path/you/seek'] = array( //...) for the page callback key. The value (the part after the =>) will be the function that defines the page you are interested in.

    If the menu item array has a file key, the value of that key will be the file which defines the callback function.

    In the case of Biblio mobule and biblio_menu:
    <?php
      $items["$base"] = array(
        'title' => $base_title,
        'page callback' => 'biblio_db_search',
        // ... access callback and arguments were here
        'file' => 'biblio.pages.inc',
        // ...
      );
    </li>
     <li><h3>Read through that function for the part where it does what you're looking for.</h3>
    Hard to provide much guidance here.  Hope that the function isn't too long and the area of interest is fairly clear.

    In our example, biblio_db_search() was 64 lines long and the part of interest to us right now, the output, came at the end:
    <?php
      return biblio_show_results($result, $query_info['sort_attrib'], $query_info['args'],$inline);
    ?>
    This means our next step is to find the biblio_show_results() function (incidentally, it takes the result of a pager_query function as $result). We know it is part of the biblio module from its biblio_ prefix, and it could be in biblio.pages.inc (where we are now), biblio.module, or any file either of these includes.

    A good IDE will let you click the function name to go to it; if you have Drupal's API module installed for your development site you can get the function definition there; or if you don't have either and have trouble finding it, in a UNIX-like environment grep -nHR 'function biblio_show_results' . from the command line (terminal) at the root of the biblio module (or your module of interest, or at the root of all Drupal) will find the file and line number that the function is defined (where that text appears).

    In this case it was right in the same function.

  3. Keep reading through each function as you drill down into the part that interests you.

    In short, you may have to repeat step three several times. It's not always clear and easy.

    The biblio_show_results() function was large but around two-thirds through it became clear that it loaded the data for showing each bibliographic entry in a fairly heavy way:
    <?php
      while ($node = db_fetch_object($result)) {
        $count++;
        $node->biblio_contributors = biblio_load_contributors($node->vid);
        // ...
        // eventually it sends it through a theme function
        $content .= theme('biblio_entry', $node,$base,$style,$inline);
      } //end while
    ?>

    The theme() call means it can be overwritten and that the original defined function should be found at theme_biblio_entry(), which we found in the biblio_theme.inc file. And for its main work it calls theme_biblio_style(), which pulls up the style include file from the biblio directory matching the $style string.

And the conclusion of this story is we went and collected and themed the autocomplete stuff completely differently.

Resolution

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <blockquote> <small> <h2> <h3> <h4> <h5> <h6> <sub> <sup> <p> <br> <strike> <table> <tr> <td> <thead> <th> <tbody> <tt> <output>
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.