Apr, 2015
selvam's picture

0 Comments | Submitted by selvam

Drupal has a solid Ajax interface, we can hook into the Ajax events at various places. I will explain some 5 important methods,
1) beforeSerialize - called before data is packed and runs before the beforeSend & beforeSubmit
2) beforeSubmit - called before the ajax request
3) beforeSend - called just before the ajax request
4) success - called after ajax event returns data
5) complete - called after the request ends
Lets say you want to capture some ajax event (in built or made by other module) to do some event like Views refresh. We can use a very simple logic to do that.

Read more →

Apr, 2015

0 Comments | Submitted by Gurumoorthi

This blog describes how to hide "Promoted to front page" and "Sticky at top of lists" options from node editing page in Drupal. When adding or editing a node, you can see "Publishing options" at bottom of the page which contains 'Published', 'Promoted to front page' and 'Sticky at top of lists' checkbox options. The below image shows you the three options:
   Disable promoted to front page and sticky at top of lists options
The "Published" option is used to publish the content. The "Promoted to front page" option is used to display content in the front page. The 'Sticky at top of lists' option is used to keep the content sticked to the top of front page. If you don't need to show "Promoted to front page" and "Sticky at top of lists" options, then you can hide those options easily. You can hide these options by altering the form either using either hook_form_alter() or hook_form_form_id_alter().
 * Implement hook_form_FORM_ID_alter().
function kf_form_article_node_form(&$form, $&form_state) {
  // hide promoted to front page option
  if (isset($form['options']['promote'])) {
    $form['options']['promote']['#access'] = FALSE;

  // hide sticky at top of lists option
  if (isset($form['options']['sticky'])) {
    $form['options']['sticky']['#access'] = FALSE;

Read more →

Apr, 2015
Pathirakaliappan's picture

1 Comments | Submitted by Pathirakaliappan

Keeping your drupal modules folder very clear is important part of development. This is the common structure :

  • Contrib - modules from Drupal.org
  • Custom - modules developed for the specific project
  • Features - exported features for Features-driven development

This structure will give better understanding about the modules to other developers and prevent them from hacking the Drupal's contributed modules.

In my case, all the contrib, custom, features were placed in single folder (sites/all/modules/). So the modules folder had nearly hundred modules, its too irritating for any developer. So I planned to move all the modules to their corresponding folders according to the common drupal folder structure. There were many issues after moving all the modules into specific folders.

Drupal's Registry rebuild module gave the opportunity to clear the registry through cli (drush/php) 

  1. Backup your database,
  2. Download and place the registry_rebuild module into your drupal modules folder,
  3. Move all the modules into their corresponding folders,
  4. Run drush rr command to clear all the registry in the database.

After clearing the registry the site is working like a charm, and its a big relief for any developer. 

Read more →

Mar, 2015

0 Comments | Submitted by Gurumoorthi

This blog describes how to solve PDOException - SQLSTATE[22003] - Numeric value out of range: 1264 Out of range. When you try to store large integer value in 'integer' field type, then you will get this error. It is because the maximum value of 'integer' field type is exceeded. 
For example, you want to store phone number in a content type. Then you may create new field with 'integer' field type in the content type. When you store 10 digit phone number in this field, "PDOException error" will be shown. MySQL allows you to store values from -2147483648 to 2147483647 in integer field type if signed, so you can't store phone number in 'integer' field type. MySQL allocates 4 bytes for 'integer' field type ie.,
4 bytes = 4 x 8 = 32 bits
2^32 => 4294967296 values
2^32 - 1 => 4294967295 (if unsigned, 0 to 4294967295 values)
-2^(32 - 1) to (2^(32 - 1) - 1) => -2147483648 to 2147483647 (if signed, -2147483648 to 2147483647 values).
If you want to store large integer value, then you need to use field type either 'bigint' or 'text field'. If you choose 'bigint', then there is no need to add custom validation for phone number field. On the other hand, if you choose 'text field' then you need to add custom validation using either hook_form_alter() or hook_form_form_id_alter().
 * Implement hook_form_alter()
function kf_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'your_form_id') {

Read more →

Mar, 2015
vishnu's picture

1 Comments | Submitted by vishnu

If you know the file id, it is really simple,

$file = file_load($fid);
file_move($file, 'public://new_file_name);

How it works:

We need a source file object to move file to the new location and update the files database entry. Moving a file is performed by copying the file to the new location and then deleting the original. To get source file object, we can use file_load() function.
file_load($fid) - loads a single file object from the database
$fid - file id
return object representing the file, or FALSE if the file was not found.

After that, we can use file_move() function to move the file new location and delete the original file..

file_move($file, 'public://new_file_name)

Parameter1 - Source File Object
Parameter2 - A string containing the destination that $source should be moved to. This must be a stream wrapper URI.
Parameter3 - Replace behaviour (Default value : FILE_EXISTS_RENAME)

For more details, check here.

Read more →

Subscribe to RSS - Drupal planet