Tag: drupal 7

  • Drupal 7 schema & datetime

    Drupal 7 schema & datetime

    When working on db schemas in Drupal it’s good to know that syntax for datetime is somewhat changed. Before it (Drupal 6) it was: ‘type’ => ‘datetime’, now in Drupal 7 it’s: ‘mysql_type’ => ‘datetime’, // for mysql

  • Replace menu links in Drupal 7 using menu_link & menu_tree hooks

    Replace menu links in Drupal 7 using menu_link & menu_tree hooks

    Want to add span elements to menu, change ul id or add classes? Need images in menu or some custom style? You can do that by using menu_link for menu items and menu_tree hook for menus itself. To replace all menus remove __MENUNAME. // Customize menu li & links function MYTHEME_menu_link__MENUNAME($variables) { $element = $variables[‘element’];…

  • Requiring files in Drupal 6 & 7

    Requiring files in Drupal 6 & 7

    I have seen a lot of Drupal modules where requiring php files is done like this $module = ‘my_module’; require_once(DRUPAL_ROOT . ‘/’ . drupal_get_path(‘module’, $module) . ‘/test.php’); While this is totally right i still encourage you to use special function for this called “module_load_include“. module_load_include(‘php’, ‘my_module’, ‘test’);

  • Logging in Drupal 7

    Logging in Drupal 7

    In case you need to log errors and other messages  in Drupal 7 use may use it’s watchdog function. Same thing will work for Drupal 6. watchdog($type, $message, $variables = array(), $severity = WATCHDOG_NOTICE, $link = NULL) Example with some data: watchdog(‘Booking’, ‘Sucessfully booked for %persons’, array(‘%persons’ => 5), WATCHDOG_INFO); Some possible severity levels are WATCHDOG_EMERGENCY,…

  • Adding content programmatically in Drupal 7

    Adding content programmatically in Drupal 7

    Sometimes you really need to add content programmatically and here’s a little sample about the basics. $node = new stdClass(); // Set content type $node->type = ‘article’; // Prepare defaults node_object_prepare($node); // Define language (currently language neutral) $node->language = LANGUAGE_NONE; // Basic content $node->title = ‘Test’; $node->body[$node->language][0][‘value’] = ‘Body text’; // Example if using custom…