Tuesday, August 23, 2011

How will you add the query string in url using l() function?

If you want to use the l() function and provide the destination:

('Login first','user/login', array(
'query' => array(
'destination' => 'node/'. $node->nid
)
)
);
?>

The above code will provide you with an anchor tag with the href pointed to user/login?destination=node/NID

This is only useful if you are linking to a page that consist of a form, and you want the user to be redirected to another page after submitting the form.


Ref: http://api.drupal.org/api/drupal/includes--common.inc/function/l/6

Tuesday, August 16, 2011

How to send email notification to the user email?

Here is the important line :

_user_mail_notify('register_no_approval_required', $account);

@"register_no_approval_required'" is the email template id.

@$account is the drupal user object.

if (user_load(array('mail' => $form['#post']['submitted']['email'])) == FALSE) {

$newUser = array(
'name' => $form['#post']['submitted']['name'],
'pass' => $form['#post']['submitted']['pass'], //user_password(),

// note: do not md5 the password
'mail' => $form['#post']['submitted']['email'],
'status' => 1,
'init' => $form['#post']['submitted']['email'],
'roles'
'roles' => array('4' => 'school')
);
$account = user_save(null, $newUser);
_user_mail_notify('register_no_approval_required', $account);
}

Sunday, August 7, 2011

how to assign new variables available in views?


function garland_preprocess_views_view__my_view(&$variables) {
$variables['foo'] = 'some text';
}

And in the tpl file I now have a $foo variable available, as you would expect having read the preprocess function page. So in the tpl file you can do this:

Views and theme override function

function theme_views_view_VIEWNAME($view, $type, $nodes, $level = NULL, $args = NULL);
When Views attempts to display a view, first it attempts to call theme('views_view_VIEWNAME'). If this function does not exist, then it will call theme('views_view'), which is the default method of displaying a view. As a themer, you can override either one, but in general it's better to override the specific one.

The $view argument will be the full definition of the view from the database.

The $type argument will be either 'block', 'page' or 'embed'. (It can actually be other things, but anything else will be user defined. More on this later). This argument is used to control whether page or block specific display is done.

The $nodes argument will be an array with all of the information from the database nicely loaded.

if $level is set to a positive value, this means the view is a summary view, and should be sent to the summary theme instead of the normal type theme.

/**
* Display a view.
*/
function theme_views_view($view, $type, $nodes, $level = NULL, $args = NULL) {
$num_nodes = count($nodes);

if (
$type == 'page') {
drupal_set_title(filter_xss_admin(views_get_title($view, 'page')));
views_set_breadcrumb($view);
}

if (
$num_nodes) {
$output .= views_get_textarea($view, $type, 'header');
}

if (
$type != 'block' && $view->exposed_filter) {
$output .= views_theme('views_display_filters', $view);
}

$plugins = _views_get_style_plugins();
$view_type = ($type == 'block') ? $view->block_type : $view->page_type;
if (
$num_nodes || $plugins[$view_type]['even_empty']) {
if (
$level !== NULL) {
$output .= "
. $view->name) ."'>". views_theme($plugins[$view_type]['summary_theme'], $view, $type, $level, $nodes, $args) . '
'
;
}
else {
$output .= "
. $view->name) ."'>". views_theme($plugins[$view_type]['theme'], $view, $nodes, $type) . '
'
;
}
$output .= views_get_textarea($view, $type, 'footer');

if (
$type == 'block' && $view->block_more && $num_nodes >= $view->nodes_per_block) {
$output .= theme('views_more', $view->real_url);
}
}
else {
$output .= views_get_textarea($view, $type, 'empty');
}

if (
$view->use_pager) {
$output .= theme('pager', '', $view->pager_limit, $view->use_pager - 1);
}

if (
$output) {
$output = "
. $view->name) ."'>$output
\n"
;
}
return
$output;
}
?>

function theme_views_summary_VIEWNAME($view, $type, $level, $nodes, $args);
If a given view has a summary mode -- in which a listing of possible choices for arguments are given -- theme('views_view_summary_VIEWNAME') will be called instead. This is a very good choice to override, because views doesn't really give the admin many options for how to display this, and there are many different possibilities.

$view contains the database view information.

$type contains the same information as theme_views_view().

$level is a number stating which argument this summary is for, starting from 0. If a view has multiple arguments (for example, view/archive/year/month/day) the summary could be for the year (0), the month (1) or the day (2).

$nodes will be an array of database information for the summary.

$args will be the arguments actually present; in the above example will be an empty array if $level = 0, but will contain the year if $level = 1 and the year and the month if $level = 2.

/**
* Display a summary version of a view.
*/
function theme_views_summary($view, $type, $level, $nodes, $args) {
foreach (
$nodes as $node) {
$items[] = views_get_summary_link($view->argument[$level]['type'], $node, $view->real_url) . " (" . $node->num_nodes . ")";
}
if (
$items) {
$output .= theme('item_list', $items);
}

return
$output;
}
?>

function theme_views_more($name);
This simple theme function formats the 'more' link.
/**
* Format the 'more' link for a view. Personally I prefer [More] but I've
* been convinced to go with simply 'more'.
*/
function theme_views_more($url) {
return
"";
}
?>
function theme_views_handle_field_TABLENAME_FIELDNAME($fields, $field, $data);
You can theme each piece of individual data by overriding this theme function. Do so with care, as using it properly requires understanding what the data you're receiving is.
/**
* Themeable function to handle displaying a specific field.
*/
function theme_views_handle_field($fields, $field, $data) {
$info = $fields[$field['fullname']];

if (
$field['handler'] && function_exists($field['handler'])) {
return
$field['handler']($info, $field, $data->$field['queryname'], $data);
}

if (
$info['handler'] && is_string($info['handler']) && function_exists($info['handler'])) {
return
$info['handler']($info, $field, $data->$field['queryname'], $data);
}

return
check_plain($data->$field['queryname']);
}
?>
function theme_views_filters_VIEWNAME($form)
For 4.7: This theme function lets you change how the exposed filters are displayed.
function theme_views_filters($form) {
$view = $form['view']['#value'];
foreach (
$view->exposed_filter as $count => $expose) {
$row[] = form_render($form["op$count"]) . form_render($form["filter$count"]);
$label[] = $expose['label'];
}
$row[] = form_render($form['submit']);
$label[] = ''; // so the column count is the same.
return theme('table', $label, array($row)) . form_render($form);
}
?>
For 5.x: This theme function lets you change how the exposed filters are displayed.
function theme_views_filters($form) {
$view = $form['view']['#value'];

foreach (
$view->exposed_filter as $count => $expose) {
$row[] = drupal_render($form["op$count"]) . drupal_render($form["filter$count"]);
$label[] = $expose['label'];
}
$row[] = drupal_render($form['submit']);
$label[] = ''; // so the column count is the same.

// make the 'q' come first
return drupal_render($form['q']) . theme('table', $label, array($row)) . drupal_render($form);
}
?>

The savvy reader will note that a large section of this documentation has, in fact, disappeared. Most of it was rendered irrelevant by the compartmentalization of the theming functions. It is the author's hope that the code snippets will be sufficient to guide you into what needs to be done, and that later tutorials can provide more interesting information.

http://drupal.org/node/42597

Ref: