Your own api.drupal.org site

I decided to spend the evening figuring out how to make my own copy of api.drupal.org so that if it should ever become unavailable, I wouldn't be stuck. Hopefully this will help other people as well. :)

Step 1: Gathering the files

You'll need two things:

  1. A copy of the API module; found in the contributions repository, under /modules/api/
  2. A copy of the development documentation; found in the contributions repository, under /docs/developer/. i suggest checking this out from CVS.

Step 2: Installation

  1. Install the api modules as usual.
  2. Enable the API module, by going to administer > modules, checking the Enable box next to the api module, and finally clicking Save Configuration. This will give you two additional menu items: API reference (at the very top) and administer > API reference (for 4.7.x) or administer > Site configuration > API reference (for 5.x).

Step 3: Indexing

  1. Go to administer > API reference (for 4.7.x) or administer > Site configuration > API reference (for 5.x).
  2. Under branches to index, enter a Short name, Long name, and Directory for your Drupal installation. For example, my Drupal installation is from HEAD, so I entered:
  3. Short name: HEAD
    Long name: Drupal HEAD

    Directory: /absolute/path/to/your/drupal/installation (in my case, this was /home/username/drupal) -- Make sure to leave off the trailing slash!

    Click Save changes when finished.

  4. Repeat for any other Drupal branches you might have installed. In my case, I only had one, so I left it as-is.
  5. Next, click the Index PHP manual pages button. This will parse PHP-specific function names and so on so they can be referenced in the code samples.
  6. NOTE: My host has disabled remote use of file_get_contents() for security reasons, so I had to replace line 13 in parser.inc with cURL function calls:

    //$source = file_get_contents($location);
      $ch = curl_init();
      curl_setopt($ch, CURLOPT_URL, $location);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
      $source = curl_exec($ch);
      curl_close($ch);

  7. Click Reindex to tag all files for reindexing. A message will appear at the top notifying you that this has been done, and informing you that the index will be rebuilt during the next few runs of cron.php. Waiting for cron.php will take way too long, though (it only indexes 10 files at a time, and cron.php runs every hour). Sooo...

Step 4: Finishing touches

  1. Instead, open the link to cron.php and reload the page numerous times, until you quit seeing messages like Parsing "/some/path/somefile.ext".... For me, this was after about 10 or so refreshes, but it will probably be much more if you have a full-featured Drupal installation.
  2. Finally, and I have no idea why this is, but it seems you have to go back to administer > modules and Save Configuration again. After that, clicking on API reference up at the top will supply a sub-menu containing whatever long name(s) you entered in the previous steps, which will then take you to the documentation for your installation of Drupal (without this step, API reference is just a blank page).

And voila!

The one thing I couldn't get working were the example modules (e.g. "How to define blocks"). They're in the /module/developer/examples/ folder, but for some reason don't match up with where the API module thinks they should be. Any hints anyone might have would be greatly appreciated. :)

Notes from chx. For me, example modules worked fine. But I needed to raise PHP memory limit significantly.

Missing step

Matt Fleming - June 27, 2006 - 13:13

I think you missed a step. In order to see anything (when you click on the 'Drupal HEAD' link), you need to copy the developer folder (from docs/developer) to the root of your drupal site. I do this in Step 2, as #3.. in other words, before indexing.

Contribution Repository

lucciano - July 26, 2006 - 15:50

From Contributions repository You can get the repository with this command
with the command

cvs -z6 -d:pserver:anonymous:anonymous@cvs.drupal.org:/cvs/drupal-contrib checkout contributions

Just the docs, ma'am

JohnAlbin - September 25, 2006 - 23:40

Or if you don't want all the contributed modules and just want the docs/developer stuff...

cvs -z6 -d:pserver:anonymous:anonymous@cvs.drupal.org:/cvs/drupal-contrib checkout -r DRUPAL-4-7 -d developer contributions/docs/developer

Some notes: You can change DRUPAL-4-7 to HEAD if you want head versions instead of 4.7 versions. And the -d developer saves it into a new developer folder instead of the full contributions/docs/developer folder tree.

Update this to 5.x?

Arancaytar - June 20, 2007 - 00:46

I was already wondering about the need to replace file_get_contents (which my host blocks as well) with cURL - "doesn't Drupal have it's own http client?" Sure enough, the relevant code in the current api module has since been replaced by drupal_http_request. :)

I have installed api on

voipfc - January 25, 2008 - 18:17

I have installed api on Drupal 5.5 and in all cases the section labelled Components for Drupal, the hook section always comes up with Page not Found whenever I click on the links.

What could I be missing?

It is only the links in that section that are not working.

===============================
===============================
Yoga Redux, Yoga for Geeks
A True Story

clean URLs

Jo Wouters - February 1, 2008 - 11:59

Make sure clean URLs is activated when running the cron-job. Otherwise you developers-page is messed up with broken links.

adding a main page

seanburlington - May 9, 2008 - 11:27

After installing the module I came across this message

A main page for this branch has not been indexed. A documentation comment with @mainpage {title} needs to exist

What took me a little while to figure out is that the comment can be in any indexed page - the developer docs have a separate file called index.php - but this isn't required.

The title must be the same as the "Long name" in the api settings.

Also it's important to enable the API search and API navigation blocks (in admin/build/block)

For me it makes sense to have a separate drupal installation for my API documentation - this is configured to index the documentation of the other Drupal installations that exist on the same machine.

Sean Burlington
www.practicalweb.co.uk
London

don't need a separate drupal installation

DynV - May 11, 2008 - 18:26

For me it makes sense to have a separate drupal installation for my API documentation - this is configured to index the documentation of the other Drupal installations that exist on the same machine.seanburlington

Instead of pointing to the root of my installation where a lot module that I don't need to make documentation on thus wasting resources on (undestanding your intention of making a separate drupal installation), I simply point to the modules which I need documentation and separate them as in the help text with colons(":").

yes ... but

seanburlington - May 15, 2008 - 11:26

Absolutely you don't need a separate Drupal install

The reasons I have done this

  1. document all code for each Drupal installation I use (one place to look and cross references work)
  2. use a different theme
  3. keep all api data out of my production databases

Sean Burlington
www.practicalweb.co.uk
London

 
 

Drupal is a registered trademark of Dries Buytaert.