In Drupal 6, there is only one hook used for all block operations but now in Drupal 7 there are different functions for different operations of the blocks. This are the hook method provided by drupal 7 for build a block.
Here we will discuss through different steps.
Step : 1
We need to create a directory in this path "sites/all/modules". i.e you need to create a new module folder inside drupal directory. Directory name must under-stable and meaningful related to your module purpose. I will named as "customblockmodule" for module directory.
We should have this two files inside directory.
Step : 2
Now we have to write a content for customblockmodule.info file.
Here we have mentioned name,description,core and package. Core will have the drupal version for this module and package will define the area of module to be placed in module section.
Step : 3
In this module file, First we have to mention about info method
hook_block_info() : This is used to tell Drupal about the new block or blocks that we will create. Drupal will display the block in the block list in the admin.
An implementation of hook_block_info() takes no arguments and is expected to return an associative array.
This defines a block named “custom_bk_module” that has two properties:
Info: This provides a description about the block. The text is used on block list in admin.
Cache: This tells Drupal how to cache the data from this block. In above example, I mentioned DRUPAL_NO_CACHE which tells Drupal not to cache the block.
hook_block_view() : Will demonstrate about view of the block. It will hold the content of the block. When page requesting to view a block, this method will get called.