Tips for getting familiar with Drupal code

When you want to code something for drupal, you'll have to familiarize yourself with the api and figure out where to put the code. As I dove deeper into development, I found some nice tricks to figure out where I am and what I can do with the classes I'm looking at.

  1. Use an IDE

    One big benefit is syntax and error highlighting which will help you avoid easy mistakes that can trip you up. Another is that you can navigate through the code by clicking on the class names and objects from the file you have open, which helps you look up things you need like function parameters. IDEs have many tools and shortcuts that will boost your productivity if you take the time to learn them.
  2. Understand the API (api.drupal.org)

    This site is developer documentation, generated from comments in the code itself. The front page has links to useful info, but for the rest, you can actually access by looking for the right file in your IDE.

    Search your site directory for *.api.php files. These provide documentation on how developers can modify a module, including core parts of the system.

    You can jump to a class's interface file to read more about it, where the comments are that define the functions. Otherwise you will just see {@inheritdoc}.
  3. Find examples in the code. If you need to know how something is used, search for it to find where it is called in other classes. You may even put a breakpoint in there to inspect the variables that need to be passed to a function.

 

More to follow...