Posts Tagged ‘Drupal’

Get parameters in url by arg(?) in Drupal

Monday, February 8th, 2010

Get parameters in url by arg(?) in Drupal

Parameters,URL,Drupal

You can easily get the url segment using function arg(?) in Drupal.

For instance:

URL: http://mysite.com/node/150349/edit

arg(0) results ‘node’
arg(1) results ‘150349′
arg(2) results ‘edit’

How to set the module weight in Drupal

Monday, February 8th, 2010

Drupal Hook Execution Order

Hook,Drupal,Order

Drupal widly uses the hook functions. If some hooks dependente on the other hooks, but they executed
before the dependence, it will show the error result. We should set the executation sequence of
the same hooks.

Add the following code in the module.install file:

/**
* Implementation of hook_install().
*/
function hide_clinet_relationship_install() {
// Set the module’s weight high so that it runs after other modules.
db_query(“UPDATE {system} SET weight = 9999 WHERE name = ‘hide_clinet_relationship’ AND type = ‘module’”);
cache_clear_all();
}

So the hooks in module hide_clinet_relationship will execute at last.

How to switch database in Drupal

Friday, January 22nd, 2010

db_set_active(‘tm’);

db_set_active(‘default’);

//Add in settings.php

$db_url['default'] = ‘mysql://root@localhost/translia_test’;
$db_url['tm'] = ‘mysql://root@localhost/tm’;

Make user inputed variables translatable in drupal

Sunday, January 10th, 2010

Add variables in settings.php

$conf['i18n_variables'] = array(
// Site name, slogan, mission, etc..
’site_name’,
’site_slogan’,

);

or if it is your module you can do like this:

/**
* Implementation of hook_init().
*/
function uc_cart_init() {
global $conf;
$conf['i18n_variables'][] = ‘uc_cart_breadcrumb_text’;
$conf['i18n_variables'][] = ‘uc_cart_help_text’;
$conf['i18n_variables'][] = ‘uc_cart_new_account_details’;
$conf['i18n_variables'][] = ‘uc_checkout_instructions’;
$conf['i18n_variables'][] = ‘uc_checkout_review_instructions’;
$conf['i18n_variables'][] = ‘uc_continue_shopping_text’;
$conf['i18n_variables'][] = ‘uc_minimum_subtotal_text’;
$conf['i18n_variables'][] = ‘uc_msg_continue_shopping’;
$conf['i18n_variables'][] = ‘uc_msg_order_existing_user’;
$conf['i18n_variables'][] = ‘uc_msg_order_logged_in’;
$conf['i18n_variables'][] = ‘uc_msg_order_new_user’;
$conf['i18n_variables'][] = ‘uc_msg_order_submit’;
}

Make your contributed drupal modules translatable in translate interface of i18n

Sunday, January 10th, 2010

For variables in your codes:
Step 1:

/**
* Implementation of hook_locale().
*/
function casetracker_locale($op = ‘groups’) {
switch ($op) {
case ‘groups’:
return array(‘case_tracker’ => t(‘Case Tracker’));
}
}

Setp 2:
if(module_exists(‘i18nstrings’)) {
$options[$state->csid] = tt(‘case_tracker:state:’. $state->csid .’:options’, $state->name, NULL, 1);
}
else
{ … }