Drupal API : Is she a monster?
From my small experience I have the feeling that the Drupal is mainly for developers. But one with high experience in non-Drupal PHP programing, will experience a starting trouble in Drupal development . They may complain that the drupal is complex because of the huge API. I have read some where a professional wrote : “Miss. Drupal, we are not born to study your API”. I admit that to a small extent. But is her API a monster?
For me the normal PHP coding style is like Bachelor's wild life where it always have enormous strength , no boundaries and wild ambitions. But my married friends said me that they love their married family life because of its own strength points. Then iI would like to call the drupal development is like the married family life. When we develop a drupal module we will have to use the API’s. First it may give you some problems & slow pace in your development. But as you proceed I am sure that One will start to love her API. After this when we switch back to plain PHP method we will find that you really miss Drupal API.
Comparing CMS systems like Joomla, magento,Drupal I have realized that when you have to add or remove something with out hacking the original code, Drupal have the easiest method because of its well defined API.
When we want to alter a form in Drupal.
In our own module which will have a module_name.module file you can write the code provided below. The module_name.info file will have a 10-15 lines.
<?php
<?php
function my_module_form_alter(&$form, $form_state, $form_id){
switch ($form_id){
case'user_adjustments_form':
$form['gen_pet_name'] = array(
'#type' => 'submit',
'#value' => t('Generate'),
'#weight'=>10,
);
$form['#validate'][]='gen_pet_name_validate';
$form['#submit'][]='gen_pet_name_submit';
break;
}
}
?>
?>
will add a button “Generate ” to the form ‘user_adjustments_form’. In the function ‘gen_pet_name_submit’ we can write the submit actions. In ‘gen_pet_name_validate’ you can put your validating actions.
In the PHP development usually you will come across the table creation, pager, database queries etc
At that time you can simply use (according to the situations)
<?php
// For tables and pagers
$output_table.=theme('table', $header, $body,array('class' => 'my_style’'),'Table heading');
$output_table.=theme('pager', NULL, 15, 5,null,10);
// For updating or inserting database queries
db_query("UPDATE {table_name} SET subject = '%s', body = '%s'",$subject,$body);
if (!db_affected_rows()) {
db_query("INSERT INTO {table_name} (subject,body) VALUES ('%s','%s')",
$subject, $body);
}
?>
Please look that 3-5 lines do the job .Isn’t that really nice? This is not that easy in case of systems like Joomla and Magento. Yes , it is right that these other families have their own strengths, mess exactly like Drupal family. But for developing Drupal provide some shortcuts. Through her API’s she is restricting you but provides another disciplined way to open up to communicate with your “family members “ and with other families.
In drupal there are some modules like Rules Views ,panels,OG &CCKwhich provide some additional powerful features to your CMS. I hope other CMS systems will adopt something like these
Everybody should take some Bachelor's life. All should go wild, do some awesome.But getting a married life will make your life better... I am sure. And joining Drupal family will be an excellent option.
WISH YOU A VERY HAPPY MARRIED LIFE...