Drupal 7

Drupal entities

When installing a fresh Drupal 7 site, there are five different entities available. You can see which entities are available by using entity_get_info().

Create a block

Basically all we need is hook_block_info() and hook_block_view() to create a block. 
By using hook_block_info() we declare which blocks are avaialable in our module. As seen on admin/structure/block. 
Hook_block_view() handles the rendering part of the block.

Handle multiple wrappers on an ajax callback

In this case the complete form is rebuild and the original messages array is replaced by the messages array related to the new form state. 

Create a lightweight commerce cart block

We build a custom block and use hook_theme to render the cart data. Usually a view is made to create a custom shopping cart block. However, a custom block to render number of items and the total price of an order is more exciting to make and more performant than a view.

Redirect on a form submit

Redirect after a form submit, with or without querystring.

Keep form values after form submit

Sometimes form state values need to be kept to keep filter values on a form submit. In order to do this, the $form_state['rebuild'] boolean has to be set to true. This is done in the submit handler of the form.

Create a block with a form


/**
 * Implements hook_block_info().
 */
function MY_CUSTOM_MODULE_block_info() {
   
  $blocks['MY_CUSTOM_BLOCK'] = array(
    'info' => t('My custom block title as shown on admin/structure/block'),
  );

  return $blocks;

}

/**
 * Implements hook_block_view().
 */
function MY_CUSTOM_MODULE_block_view($delta) {

  switch ($delta) {
    case 'MY_CUSTOM_BLOCK' :
      return array(
      'subject' => t('MY_CUSTOM_BLOCK title.'),
      'content' => drupal_get_form('MY_CUSTOM_FORM'),
      );
      break;
  }
   
}

/**
 * Implements hook_form().
 */

Create a page

Create a page which can only be accessed by user roles with the appropriate permission.

Pages

Subscribe to RSS - Drupal 7