Friday, February 18, 2011

Customizing the Search form - Drupal


To change the label text and text inside the search box and the text on the submit and changing the Submit button image, you can use the following function to do the customizations. You have to add this code in template.php file.

function mytheme_preprocess_search_theme_form(&$vars, $hook) {
// Change the "Search this site" label from the form.
$vars['form']['search_theme_form']['#title'] = t('googling');

// Set a default value for text inside the search box field.
$vars['form']['search_theme_form']['#value'] = t('Find it ..');

// Add a custom class and placeholder text to the search box.
$vars['form']['search_theme_form']['#attributes'] = array('class' => 'NormalTextBox txtSearch', 'onblur' => "if (this.value == '') {this.value = '".$vars['form']['search_theme_form']['#value']."';} ;", 'onfocus' => "if (this.value == '".$vars['form']['search_theme_form']['#value']."') {this.value = '';} ;" );

// Change the text on the submit button
//$vars['form']['submit']['#value'] = t('Go');

// Rebuild the rendered version (search form only, rest remains unchanged)
unset($vars['form']['search_theme_form']['#printed']);
$vars['search']['search_theme_form'] = drupal_render($vars['form']['search_theme_form']);

$vars['form']['submit']['#type'] = 'image_button';
$vars['form']['submit']['#src'] = path_to_theme() . '/images/search.gif';

// Rebuild the rendered version (submit button, rest remains unchanged)
unset($vars['form']['submit']['#printed']);
$vars['search']['submit'] = drupal_render($vars['form']['submit']);

// Collect all form elements to make it easier to print the whole form.
$vars['search_form'] = implode($vars['search']);
}

Wednesday, February 16, 2011

Dfont module - Drupal

The Dfont module is very useful. This module is very useful in cases like when the Client needs the Site in particular font which is also a rare font which wont be available in most of the Users machine, so in that case only the default font will get called this is where the issue raises. In this case few options available are,
  •  We can add the fonts as images, but you cant add every text as Images then the site will be very slow.
  •  Another thing is embedding flash which is also not a good option.
  •  Compartively the Dfont module option is Good. You need to add that font to the server, from there the font will get called, the user's machine doesnt need to have that Font. Therefore every user can view the site in Client requested Font.

Steps for installing this module,
  •  Enable the module asusual.
  •  After enabling, go to the dfont settings page (admin/settings/dfont), there also the instructions will be available.
  •  The Next step is you have to Upload the .ttf and .eot files, for each font, to directory sites/default/files/fonts.
  •  Then Scroll down and click Generate font styles.
  •  Then Enable dynamic font filter in admin/settings/filters and Refresh this page to ensure your fonts are rendered below.

You can download the fonts from http://www.tti-us.com/uvn/p_buyscript.htm. Also to convert the fonts to .eot format, you can use this link to do that http://www.kirsle.net/wizards/ttf2eot.cgi.

Then you have to add some Css properties for including the font family, size etc ...
Ex:
h1, h2, h3, h4, h5, h6 {
   font-family: UVNDamCuoi_H;
}

"UVNDamCuoi_H" is the Font name (which I have used). So after including this, automatically all the header tags (h1,h2 etc ..) will be displayed in the "UVNDamCuoi_H" font. You can also use the default options like [dfont=df1m],[dfont=df1l],[dfont=df1x] in the dfont settings page for various presets.

Tuesday, February 15, 2011

Floating Blocks - Drupal

The Floating block module allows you to keep html blocks or contents, selected using jquery selectors in a fixed position on the page as you scroll.  This means that when a user scrolls the browser, some parts of the site can be maintained in the user's view by fixing their position.

Install the module asusual.
Go to the Floating block admin settings page (admin/settings/floating_block), there you will find a Textarea where you can enter the CSS classes or Id's of the blocks which needs to be floating.

Examples :
#block-chatroom-0
#search
#myarea

It has to be entered one by one as above, as you can see the first and second Css Id's are drupal blocks from contributed modules while the third one is customely added DIV by me, which means it also works for the Custom DIV's or regions not only the Drupal Blocks.

Friday, February 11, 2011

Drupal - Module hooks invoke procedure


How does all the hooks inside all the modules (custom & contributed) gets invoked and executed,

module_implements() - this is the function which Determine which modules are implementing a hook.

function module_implements($hook, $sort = FALSE, $refresh = FALSE) {
  static $implementations;

  if ($refresh) {
    $implementations = array();
    return;
  }

  if (!isset($implementations[$hook])) {
    $implementations[$hook] = array();
    $list = module_list(FALSE, TRUE, $sort);
    foreach ($list as $module) {
      if (module_hook($module, $hook)) {
        $implementations[$hook][] = $module;
      }
    }
  }


In this function it will call the module_list() function which returns all the enabled modules, further on which module_hook() function is called which checks whether the module uses that hook function

function module_hook($module, $hook) {
  return function_exists($module .'_'. $hook);
}

Tuesday, February 8, 2011

Perfomance tunings for Drupal Websites


Steps to follow to increase the site's performance,

Install a PHP script cache - eAccelerator

Turn on MySQL query caching

Turn on Drupal page caching

Compress your content

combine your CSS using Css aggregator

Combine your JS using js aggregator

Y-slow can be used for checking the performance.

For more information, visit the following link

http://nadeausoftware.com/articles/2007/01/essential_performance_tuning_drupal_web_sites

Customizing the Search form - Drupal

To change the label text and text inside the search box and the text on the submit and changing the Submit button image, you can use the fo...