alter / automatize the install process

in the .profile file of the install profile (here "mysnippet" profile)

  1. /**
  2.  * Implementation of hook_install_tasks_alter().
  3.  */
  4. function mysnippet_install_tasks_alter(&$tasks, $install_state) {
  5. // Database step.
  6. $tasks['install_settings_form'] = array('function' => 'my_install_settings_form');
  7. // Site configuration
  8. $tasks['install_configure_form'] = array('function' => 'my_install_configure_form');
  9. // Install is complete
  10. $tasks['install_finished'] = array('function' => 'my_install_finished');
  11. }
  12.  
  13. /**
  14.  * Alter database form settings
  15.  */
  16. function my_install_settings_form(&$install_state) {
  17. $form_state['storage']['database'] = array(
  18. 'database' => 'mysnippet',
  19. 'username' => 'myusername',
  20. 'password' => 'mypasswd',
  21. 'host' => 'localhost',
  22. 'port' => '',
  23. 'driver' => 'mysql',
  24. 'prefix' => ''
  25. );
  26. // call the initial submit
  27. install_settings_form_submit("", $form_state);
  28. }
  29.  
  30. /**
  31.  * Alter site configuration settings
  32.  */
  33. function my_install_configure_form(&$install_state) {
  34. $form_state['values'] = array(
  35. 'site_name' => $d['name'],
  36. 'site_mail' => 'no-reply@'.$d['name'].'.cec',
  37. // uid 1
  38. 'account' => array (
  39. 'name' => 'adminRTD',
  40. 'mail' => 'admin@'.$d['name'].'.cec',
  41. 'pass' => '07adminRTD73' //$d['default_admin_pass'],
  42. ),
  43. 'site_default_country' => 'BE',
  44. 'date_default_timezone' => 'Europe/Brussels',
  45. 'clean_url' => 1,
  46. 'update_status_module' => array (
  47. 1 => 0,
  48. 2 => 0
  49. )
  50. );
  51. }
  52.  
  53. /**
  54.  * Additional tasks when install is finished
  55.  */
  56. function my_install_finished(&$install_state) {
  57. variable_set('install_profile', drupal_get_profile());
  58. db_update('system')
  59. ->fields(array('weight' => 1000))
  60. ->condition('type', 'module')
  61. ->execute();
  62. drupal_get_schema(NULL, TRUE);
  63. }

Static variable usage

there is a drupal wrapper for static variables: drupal_static()

Simple modal output with Ctools

Modal window provided by Ctools was designed to output forms but it can serve simple html as well.

Connect to an external db

Sometimes it is useful to use another database than the one installed by default by Drupal.

usefull image functions

how to get an image path or theme a preset image ?

override a default .tpl.php file in theme

To override a default .tpl.php file (to NOT use the page.tpl.php file for instance but page--mysnippet.tpl.php)

Programmaticaly insert block

to output a block created by a module in code, use:

View hooks order

The execution order of view hooks is important if you don't want your tweaks to be overridden

Drupal module list: lesser known

Huge list. I'm sure these Drupal modules will help in the future... if they are not currently used yet!! Always rely on (good...) modules built by the Drupal community than write your own!

Send an email

There is unfortunately no easy way to send an email in Drupal... and no way to send an html email using core functions!!

Firebug console error prevention

If you need to publish code that contains "console" calls (for instance console.log with firebug) and don't want javascript to be broken on browser that don't have console enabled, this function is useful: