CMS

Cache API in DRUPAL

There are two major function in DRUPAL for Cache API.

1. cache_set().
2. cache_get().

Function signature for cache_set() is:

cache_set($cid, $table = 'cache', $data, $expire = CACHE_PERMANENT, $headers = NULL)

The function parameters are:

• $cid: A unique cache ID string that acts as a key to the data.
• $table: The name of the table to store the data in. You can create your own table or use cache, cache_filter, cache_menu, or cache_page. The cache table is used by default.
• $data: The data to store in the cache. Remember that complex PHP data types must be serialized first.
• $expire: The length of time for which the cached data is valid. Possible values are CACHE_PERMANENT, CACHE_TEMPORARY, or a Unix timestamp.
• $headers: For cached pages, a string of HTTP headers to pass along to the browser.

Here is an example for cache_set() which can be seen in filter.module.

// Store in cache with a minimum expiration time of 1 day.

How Blocks are Themed in Drupal

When a page request is made, theme system ask block system for returning list of blocks for each region. It does this when preparing the variables to be send to the page template (usually page.tpl.php). For example to gather the themed blocks for the left and right sidebars, Drupal executes the following:

$sidebar_left = theme('blocks', 'left');
$sidebar_right = theme('blocks', 'right');
// And any other regions exposed by hook_regions().

theme('blocks') is actually a call to theme_blocks().

Here’s what theme_blocks() actually does:


function theme_blocks($region) {
  $output = '';
  if ($list = block_list($region)) {
     foreach ($list as $key => $block) {
       $output .= theme('block', $block);
     }
  }
  return $output;
}

In the above code snippet, we just iterate through each block for the given region and execute a theme function call for each block. Finally, we return all the themed blocks for that

Submit Function for form in Drupal

Submit function actual deals with form processing after the form has been validated. It only executes if form validation passed completely.

Retrieve Information About Terms in Drupal

Drupal have several built-in functions to retrieve information about terms as objects or as an array of objects.

Here are the list of built-in functions:

taxonomy_get_term($tid)

drupal_execute function to submit form

In Drupal,forms that are displayed in a web browser can also be filled out programmatically.

Here is an example to fill out our firstname and lastname programmatically.

$form_id = 'formexample_nameform';
$field_values = array(
   'user_firstname' => t('Kiran'),
   'user_lastname' => t('Hota')
);
// Submit the form using these values.
drupal_execute($form_id, $field_values);

Just supply the form ID and the values for the form, and call
drupal_execute().

Cumulus Tag Cloud

Kiran Says

I love work environment which is:

Informal yet professional
Demanding yet rewarding
Challenging yet inspiring
Mediocrity is not an option
Having fun is serious business
Making mistakes is human
Forgiveness is Company Policy

Travelling Sucks