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. }

override a default .tpl.php file in a custom module

to basically use a template file in a custom module use the hook_theme_registry_alter(&$theme_registry) like this

Testing date fields: strtotime tips

Unit testing the creation of a node with a date field could fail because of wrong interpretation of the date by strtotime function

Enable block

There is no available API to programmatically set a block. Like Drupal core does, we have to use db directly.

simpletest: count checkboxes checked

Sometimes it is useful to know exactly the amount of options enabled with a xpath expression

Add a conditional stylesheet for IE

the options of drupal_add_css allow the use of conditional stylesheets

debug drush (and php-cli)

Drush uses the cli version of php so traditional debugging tools and functions don't work.

Create an image style

to create in code, programmatically an image style (previously called image cache preset)

Current path alias

to get the current page alias path use

Unset core stylesheet in a custom theme

by using use hook_css_alter() in template.php