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().

Block Visibility in Drupal

Inside the block admini interface, one can enter PHP code snippets in “Page visibility settings” section of the block configuration page.
While a page being generated, Drupal will run the PHP snippet to determine whether a block will be displayed.

Examples of some of the most common snippets follow; each snippet should return TRUE or FALSE to indicate whether the block should be visible for that particular request.

Displaying a Block to Logged-In Users Only
Only return TRUE when $user->id is not 0.

<?php
   global $user;
   return (bool) $user->uid;
?>

Drupal Hooks

Hooks allow modules to interact with the Drupal core.

Module system of Drupal is based on the concept of "hooks". A hook is actually a PHP
function that is named modulename_hookname(), where "modulename" is the name of the module (whose
filename will be modulename.module) and "hookname" is the name of the hook. Every hook have
a defined set of parameters and a specified result type.

Cumulus Tag Cloud

Kiran Says

SEO Architect,SEO Specialist reflect my values.

By enduring black hat methods the SEO industry is setting itself up for washout and sleepwalking into oblivion.

Jobs in India