<?php
$items['tespage'] = array(
'title callback' => 'custommodule_get_title',
'title arguments' => array(1),
'type' => MENU_CALLBACK,
'page arguments' => array(5),
'access arguments' => array('administer customworkflow'),
);
/**
*Function to display the title dymnamically
*Parameters passed
*@param $arg
* Passing the id to get the custom name
*/
function custommodule_get_title($arg){
$arg = ($arg)?$arg:arg(1);
//Based on argument do the operation
$name = custom_get_name($arg);
return "Edit ".drupal_ucfirst($name);
}
?>
Please follow this blog if u feel the blog content is useful to you
Friday, April 22, 2011
Add a class to body tag for a particular menu
<?php
/**
* Override or insert PHPTemplate variables into the templates.
*/
//In template.php file
function phptemplate_preprocess_page(&$vars) {
if(arg(0) == "node" && arg(1) == 2){
$vars['body_classes'] = $vars['body_classes']." testing";
}
return $vars;
}
?>
/**
* Override or insert PHPTemplate variables into the templates.
*/
//In template.php file
function phptemplate_preprocess_page(&$vars) {
if(arg(0) == "node" && arg(1) == 2){
$vars['body_classes'] = $vars['body_classes']." testing";
}
return $vars;
}
?>
Change or customize the system theme for a menu callback
//Put this code to the menu callback
<?php
global $custom_theme;
$custom_theme="acquia_marina";
?>
<?php
global $custom_theme;
$custom_theme="acquia_marina";
?>
Example of drupal_render usage
<?php
//DRUPAL RENDER USAGE
$form['add_wf_mapping'] = array(
'#type' => 'button',
'#id'=>'edit-add-wf-mapping',
'#name'=>'edit-add-wf-mapping',
'#attributes' => array('style'=>'margin:0px'),
'#value' => t('Map Workflow')
);
$output .=drupal_render($form['add_wf_mapping']);
echo $output;
Output the button
?>
//DRUPAL RENDER USAGE
$form['add_wf_mapping'] = array(
'#type' => 'button',
'#id'=>'edit-add-wf-mapping',
'#name'=>'edit-add-wf-mapping',
'#attributes' => array('style'=>'margin:0px'),
'#value' => t('Map Workflow')
);
$output .=drupal_render($form['add_wf_mapping']);
echo $output;
Output the button
?>
Thursday, April 21, 2011
View unpublished content by an moderator or content editor(custom role created)
1.Create an custom module view_unpublished
2.Place this code in it
<?php
/**
* Implementation of hook_perm().
*/
function view_unpublished_perm() {
$perms = array('view all unpublished content');
foreach (node_get_types() as $type => $name) {
$perms[] = 'view unpublished ' . $type . ' content';
}
return $perms;
}
/**
* Implementation of hook_menu_alter().
*
* Modifies the path node/nid to use our access callback.
*/
function view_unpublished_menu_alter(&$items) {
$old_access_callback = $items['node/%node']['access callback'];
$items['node/%node']['access callback'] = '_view_unpublished_node_access';
$items['node/%node']['access arguments'] = array(1, $old_access_callback);
}
/**
* Returns true if the user has 'view all unpublished content' or if
* they have the permission corresponding to the node's content type.
*/
function _view_unpublished_node_access($node, $old_access_callback = "node_access") {
// Only check permissions on nodes that are unpublished.
if ($node->status == 0) {
if (user_access('view all unpublished content')) {
return TRUE;
}
if (user_access('view unpublished ' . $node->type . ' content')) {
return TRUE;
}
}
// If none of the above conditions were satisfied, then use the normal callback.
return $old_access_callback('view', $node);
}
?>
2.Place this code in it
<?php
/**
* Implementation of hook_perm().
*/
function view_unpublished_perm() {
$perms = array('view all unpublished content');
foreach (node_get_types() as $type => $name) {
$perms[] = 'view unpublished ' . $type . ' content';
}
return $perms;
}
/**
* Implementation of hook_menu_alter().
*
* Modifies the path node/nid to use our access callback.
*/
function view_unpublished_menu_alter(&$items) {
$old_access_callback = $items['node/%node']['access callback'];
$items['node/%node']['access callback'] = '_view_unpublished_node_access';
$items['node/%node']['access arguments'] = array(1, $old_access_callback);
}
/**
* Returns true if the user has 'view all unpublished content' or if
* they have the permission corresponding to the node's content type.
*/
function _view_unpublished_node_access($node, $old_access_callback = "node_access") {
// Only check permissions on nodes that are unpublished.
if ($node->status == 0) {
if (user_access('view all unpublished content')) {
return TRUE;
}
if (user_access('view unpublished ' . $node->type . ' content')) {
return TRUE;
}
}
// If none of the above conditions were satisfied, then use the normal callback.
return $old_access_callback('view', $node);
}
?>
Wednesday, April 20, 2011
change template files based on an cck or an url
Customize templates based on CCK or URL
Drupal6
<?php
function themename_preprocess_page(&$variables) {
//Templete file for each content type
if ($variables['node']->type != "") {
$variables['template_files'][] = "page-node-" . $variables['node']->type;
}
//Seperate Templete file for the path node/3
if ((arg(0) == 'node') && is_numeric(arg(1)) && (arg(2) == NULL) && arg(1)==3) {
$variables['template_files'][] = "page-test";
}
}
?>
Drupal 7
<?php
function themeName_preprocess_page(&$vars, $hook) {
if (isset($vars['node'])) {
// If the node type is "blog_madness" the template suggestion will be "page--blog-madness.tpl.php".
$vars['theme_hook_suggestions'][] = 'page__'. $vars['node']->type;
}
}
?>
Drupal6
<?php
function themename_preprocess_page(&$variables) {
//Templete file for each content type
if ($variables['node']->type != "") {
$variables['template_files'][] = "page-node-" . $variables['node']->type;
}
//Seperate Templete file for the path node/3
if ((arg(0) == 'node') && is_numeric(arg(1)) && (arg(2) == NULL) && arg(1)==3) {
$variables['template_files'][] = "page-test";
}
}
?>
Drupal 7
<?php
function themeName_preprocess_page(&$vars, $hook) {
if (isset($vars['node'])) {
// If the node type is "blog_madness" the template suggestion will be "page--blog-madness.tpl.php".
$vars['theme_hook_suggestions'][] = 'page__'. $vars['node']->type;
}
}
?>
Subscribe to:
Posts (Atom)