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
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']; $sub_menu = ''; if ($element['#below']) { $sub_menu = drupal_render($element['#below']); } // Enable this to use html in title, eg img, span or something else... $element['#localized_options']['html'] = true; $link = l('<span>' . $element['#title'] . '</span>', $element['#href'], $element['#localized_options']); return '<li' . drupal_attributes($element['#attributes']) . '>' . $link . $sub_menu . "</li>\n"; } // Customize menu ul function MYTHEME_menu_tree__MENUNAME($variables) { // Change id of menu ul return '<ul id="my-custom-menu-id">' . $variables['tree'] . '</ul>'; }
You can probably use preprocess_menu_link or preprocess_links as well, but this seems to be easiest way. Read more about it here.
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');
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 fields $node->field_CUSTOM_FIELD[$node->language][0]['value'] = 'Value'; // Example if using fields that are taxonomy type $node->field_CUSTOM_FIELD_TAXONOMY[$node->language][0]['tid'] = 1; // Save node node_save($node);
For updating nodes load them first with:
// Node id you want to update $nid = 1; $node = node_load($nid);
And if you want to use revisions add the following:
$node->revision = 1; $node->log = 'Node updated at ' . date('F j, Y, G:i');
To find out possibilities for naming template files add following line to related template hook in your template.php eg THEME_preprocess_HOOK():
print_r($variables['theme_hook_suggestions']);
Some hooks to look at _html, _page, _node, _block, _pane, _views_view_field, _comment, _search_result, _search_results, _user_profile.