Drupal 7 – Use queues for long running tasks in cron

Sometimes we may need to run some complex and time consuming tasks in Drupal cron but this may result in request timeout. It’s better to setup cron queues and run them in parallel requests.

Yesterday we have setup a hook_cron() task for batch updating nodes.
Drupal 7 – Batch update nodes by cron

Actually we can convert the tasks in the cron queues using hook_cron_queue_info() as follow.
Continue reading Drupal 7 – Use queues for long running tasks in cron

Drupal 7 – Batch update nodes by cron

The following piece of code will update a field of a specific content type by SQL and it is written in a custom module with hook_cron(). Since it updates the database table directly so you have to use it with extreme caution.
Continue reading Drupal 7 – Batch update nodes by cron

Drupal 7 – Add Javascript files on specific paths by template.php

In my previous post, Drupal 7 – Add Javascript files on specific paths by custom module, we try to add .js files for specific paths by creating a custom module. Actually we could implement the same feature by using the theme template.php. Here is an example.
Continue reading Drupal 7 – Add Javascript files on specific paths by template.php

Drupal 7 – Override the term path inside Tagadelic Tag Cloud

Implement tag cloud is easy in Drupal. You can find the module called Tagadelic in the my previous post.
Drupal 7 – Create a Tag Cloud with Tagadelic

But the term path inside the tag cloud is always fixed as default which is taxonomy/term/[tid]. I tried to override it by the Entity Path module but no luck. Luckily i find a workaround to override it. Actually Tagadelic is not just a simple Drupal module but also a API system. The following theme function theme_tagadelic_weighted() determines the term path in Tagadelic.
Continue reading Drupal 7 – Override the term path inside Tagadelic Tag Cloud

PHP – String startsWith and endsWith

The following 2 functions could check if a string starts/ends with another string.

/* Return TRUE if $needle is empty */
function startsWith($haystack, $needle) {
  $length = strlen($needle);
  return (substr($haystack, 0, $length) === $needle);
}

/* Return TRUE if $needle is empty */
function endsWith($haystack, $needle) {
  $length = strlen($needle);
  if ($length == 0) {
    return TRUE;
  }
  $start  = $length * -1;
  return (substr($haystack, $start) === $needle);
}

Please note that if the $needle is empty, both functions will return TRUE.

Done =)

Reference: StackOverflow – PHP startsWith() and endsWith() functions

Drupal 7 – Limit the number of countries in the country list of the Location module

If you want to include location information in your content type. The Location module could help. But by default, the list of selectable countries are very long and sometimes we may want to limit it to a few countries only. This can be done by creating a custom module but it only works for Location CCK but not for Node Location and User Location

1. Download and enable the Location and Location CCK modules
Continue reading Drupal 7 – Limit the number of countries in the country list of the Location module

Dream BIG and go for it =)