Saturday, January 14, 2012

PHP to Drupal: Get up to speed with drupal from a php developer background

While working on various projects with drupal I realized that there is really no one definitive place which lists the concepts that you need to become familiar with when dealing with drupal. So I decided that I would put them in one place for people who maybe are experienced php developers who are trying to learn to work with drupal for the first time.

The main important components when working with drupal on a serious project are:

1. Pages

A page is a unit that most web developers are most familiar with already. And that is the problem, because when you are creating a website with drupal, the code is not organized in these bite sized chunks. The beauty of the drupal model of work is that drupal separates what you need to write into re-usable chunks of code which can be used on numerous pages, and is not confined to one page in particular.

That being said, there are still instances where pages are used, but not in the same way as in a website you have to program from scratch. Often times pages are used instead as a means to configure areas of drupal, as admin pages etc.

2. Blocks

A block is a small chunk of code which can be placed on the same page as page content, or on a node (which I will explain next). The block is a handy thing because it is easy to put blocks across a large number of pages, and it is also possible to let the admin user configure the visibility of a block based on the user's permission level (called a user role) via the admin interface.

These properties make blocks powerful in that you can put them in almost any configuration on a page, but not care ahead of time what else is on the page. In effect leaving page design to a designer or site admin.

3. Nodes

A node is a very important part of drupal, because it ties in so deeply with the drupal structure. A node is an object in drupal. The node can be displayed and expanded and acted upon by modules. In the drupal module repository there are many modules which will act on nodes allowing for some really cool things.

The node can be a somewhat difficult concept to grasp, but thinking of it as a procedural object which can be acted upon, displayed, filtered, and restricted as a group. So a grouping of these "nodes" (known as a content type) can be exposed to different user roles. This means that if you want a bunch of pages which do the exact same thing you would create a new content type and then the individual nodes would all have the same structure.

4. Theming

Theming is important in drupal as it makes any code which is written and enables the designer to alter the output of that code, by adding tags, markup and css in order to make the website pretty. In this it is important to expose all html to drupal when you are writing it so that a designer can later open up the theme folder and overwrite your theming function adding these ever important tags.

The theming engine in drupal is quite powerful and it is possible to procedurally theme small subsets of a page consistantly on a website by using this theming technique.

5. Modules

A module is where the exciting things happen in drupal. Because as a drupal developer you will want to avoid hacking drupal core as much as possible. This makes upgrading simple and easy, as well as keeping the codebase clean for your modules, making it possible for them all to work together instead of having one module vs. another.

The module system in drupal again is very powerful because of the node structure, and drupal's ability to edit queries which are written in one area of drupal, or written in one module by another.

6. Menu

The menu structure in drupal is also important. This is the area of drupal which exposes certain menu items based on permissions, and also changes based on where you are in your website's tree structure. It is important to use the menu structure on your drupal websites because this structure is much more powerful than doing it by hand. And because of the permission based feature.

7. Testing

Going forward into drupal 7 testing is becoming increasingly important in the drupal community. This testing is becoming a part of the core list of modules, but also it is very helpful even in drupal 5 and drupal 6. Unit testing ensures that if you make changes to your code, that it does not effect the code you have already written.

There has recently been a big push for testing to increase the productivity of coding and reduce the number of errors in the code. Drupal's testing is mostly done with the simpletest module found at http://drupal.org/projects/simpletest.

So this is my broad overview of what concepts a php programmer needs to know when starting to work with drupal. Please let me know if I forgot anything.

src: http://www.westwesterson.com/blog/php-drupal-get-speed-drupal-php-developer-background

No comments:

Post a Comment