Skip to Content

Drupal

t()

In Drupal the ubiquitous "t" function is used to translate strings to a page language or a given user language. As such in module writing the "t" function should be used extensively to encapsulate all user readable text.

The "t" function works with special placeholders that signal "dynamic information" in a string that needs "extra" filtering or should not be filtered or translated at all, such as URLs. There are three different placeholders that offer three different exceptions to the normal operation of "t".

Placeholder Description
! Prevents all manipulation by "t", text is inserted as is.

APPENDIX A: Drupal 6 Function List Quick Reference

Function Name Description
actions_do
actions_list
actions_get_all_actions
actions_actions_map
actions_function_lookup
actions_synchronize
actions_save
actions_load
actions_delete
_batch_page
_batch_start
_batch_progress_page_js
_batch_do
_batch_progress_page_nojs
_batch_process

drupal_goto()

drupal_goto($path = '', $query = NULL, $fragment = NULL, 
$http_response_code = 302)

This simple function initiates an immediate redirect of the user to the URL indicated. The function contains additional parameters to handle complex URL building and supports RFC 2616 by registering an HTTP code for the redirect.

The parameters are parsed by this code fragment:

$url = url($path, array('query' => $query, 'fragment' => $fragment, 'absolute' => 
TRUE));

The array is relatively straight forward with the [0] element as the actual address, and the query(if any) loaded into an associative part of the array and the fragments(if any) also loaded into an associative part of the array.

The PHP function 'header()' does the heavy lifting in the function by setting the destination and giving the response code to the users browser:
header('Location: '. $url, TRUE, $http_response_code);

Drupal Functions Explained

This section of the guide will cover specific functions within the Drupal 6 API in a way that hopefully sheds more light on their common use.

Changing your default site theme and/or your blog theme

After registering an account with the site, you may decide you want to go with a brighter theme than the default. So the site has been populated with about a dozen alternative themes that you can set from your user account.

To do this:

  1. open the "My Account" menu
  2. select the edit option above your account information
  3. scroll down to the theme area of the settings and select the radio button of the theme you want
  4. scroll to the bottom of the page, and hit the save button

Your default theme is now changed whenever you log in.

NOTE: You may have trouble viewing all of the "extra" content with a non-standard theme.

How to use the NOVALUG website

This book covers how to use some of the sophisticated features of the site.

Don't Hack the Core

So it's important to understand early on that Drupal strives for a 'secure' and 'reliable' architecture and does so by separating the core code from user generated and contributed code. All the editable code is kept in the /sites folder of a Drupal installation. In a single site installation all this modular code is kept in /sites/all/modules or /sites/all/themes. One of the most common beginner mistakes is to look inside the new Drupal directory and use the /modules or /themesdirectory for storing downloaded modules and custom code.

The root /modules directory holds the modules that have been incorporated in the core Drupal release, this directory and all directories outside of /sites should be left alone. Drupal provides ample ways to override the behavior of the core code, and using the API's is vastly more secure and reliable than altering core code.

Can't logout of Drupal

Similarly to loosing the user login page, it's not uncommon to remove the navigation links and blocks and suddenly you can't easily logout of a Drupal site. The answer to that is also to append a page callback to the address bar of your browser, either:
http://www.mysite.com/logout
or
http://www.mysite.com/?=logout
if you don't have clean URLs turned on.

Explanation:
Same as for the lost user login block, a 'page callback' invokes a function which logs the user out of the site(see Can't login to Drupal).

Can't login to Drupal.

A common problem when building Drupal sites is to somehow get rid of the login form entirely from easily accessible areas of the site. The solution to this is to manually enter the location(page callback) of the login form in your browser address bar.

http://www.mysite.com/user
if your site has clean URLs
http://www.mysite.com/?=user
if your site does not have clean URLs

Expanation:
It is canonical to create a "page callback" for any FORMS you create in Drupal, and the user login form is no exception. Here's the Drupal version 6 code(lines 898-900 in /modules/user/user.module):

  $items['user'] = array(
    'title' => 'User account',
    'page callback' => 'user_page',

Beginners Tips

This section contains some useful tricks that will push beginners up that learning curve quite a bit faster. As best as I have time for I'll explain why these tricks work and why you should use them.

Syndicate content