Saturday, May 7, 2011

Put a pipe symbol in between primary link

1.Pu this code in the template.php file of your theme folder
2.Check the class of primary links in the page.tpl or page-front.tpl matches with class condition check indie this function if this function doesn't work

function youthemename_links($links, $attributes = array('class' => 'links')) {
$output = '';
// Change the way primary links are rendered
if($attributes['class'] == 'links primary-links') {
$linklist = array();
foreach ((array)$links as $key => $link) {
$linklist[] = l($link['title'], $link['href'], $link);
}
// Return the links joined by a '|' character
return join(' | ', $linklist);
}
// Normal theming continued below:

if (count($links) > 0) {
$output = '<ul'. drupal_attributes($attributes) .'>';

$num_links = count($links);
$i = 1;

foreach ($links as $key => $link) {
$class = $key;

// Add first, last and active classes to the list of links to help out themers.
if ($i == 1) {
$class .= ' first';
}
if ($i == $num_links) {
$class .= ' last';
}
if (isset($link['href']) && ($link['href'] == $_GET['q'] || ($link['href'] == '' && drupal_is_front_page()))) {
$class .= ' active';
}
$output .= '<li class="'. $class .'">';

if (isset($link['href'])) {
// Pass in $link as $options, they share the same keys.
$output .= l($link['title'], $link['href'], $link);
}
else if (!empty($link['title'])) {
// Some links are actually not links, but we wrap these in for adding title and class attributes
if (empty($link['html'])) {
$link['title'] = check_plain($link['title']);
}
$span_attributes = '';
if (isset($link['attributes'])) {
$span_attributes = drupal_attributes($link['attributes']);
}
$output .= '<span'. $span_attributes .'>'. $link['title'] .'</span>';
}

$i++;
$output .= "</li>\n";
}

$output .= '</ul>';
}

return $output;
}

Remove formating text & split summary cursor button in drupal

You should put this is code inside hook_alter of any your custom module
-----------------------------------------------------------------------------------------------------------

$form['body_field']['format'] = array();
$form['body_field']['teaser_include'] = array('#type' => 'value','#value' => TRUE,);

Friday, April 22, 2011

Dynamically display the title of page

<?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);
 }

?>

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;
  }
?>

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";
?>

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

?>

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);
}


?>