Block configure API in Drupal 7

In Drupal 6, there was only one signle hook_block(), which received the desired function operator ina for of an $op variable. In Drupal 7, they have broken it into separate functions, depending on that $op operator - info, view, save, configure.

1. Now, to first have to declare the block. See, that it now uses the menu system to do it:

<?php
function mymodule_block_info() {
 
$blocks['mymodule_menu'] = array(
   
'info' => t('My Module Title'),
   
'cache' => DRUPAL_NO_CACHE,
  );
  return
$blocks;
}
?>

2. If we need to add a configuration interface, to the module form, we use Forms API (FAPI):

<?php
function mymodule_block_configure($delta) {
 
$form = array();
   
   
// Define an element with FAPI
   
$form['textfield'] = array(
     
'#type' => 'textfield',
     
'#title' => t('Title'),
     
'#default_value' => 'Fill in the text here',
     
'#size' => 60,
     
'#maxlength' => 128,
     
'#required' => false,
    );
  }
  return
$form;
}
?>

3. To save the form text for further usage, both a database entry can be used, or the text can be saved as a variable (which still goes to database, but does not require creating a new table):

<?php
function mymodule_block_save($delta = '', $edit = array()) {

 
// Get the form item and security-filter
 
$text = check_plain($edit['textfield']);
 
 
// Save as a variable
 
variable_set('mymodule_title', $text);
}
?>

$delta variable, which is present in all those cases, denotes the block delta for those cases, when your module provides more that one block.