Novice

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.

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.

Programatically delete taxonomy terms Drupal 7

By calling function taxonomy_get_tree($vid, $parent = 0, $depth = -1, $max_depth = NULL), an array of all term objects is returned. Extra parameters can be added to the function to select all items belonging to a particular parent or limit depth of the tree. By calling function taxonomy_term_delete($tid), a new db_transaction() starts and the taxonomy object and all its children are deleted from the taxomy_term_data and taxonomy_term_hierarchy tables. As a taxonomy term is an entity which has attached fields, all attached field data is also deleted. Finally, the function clears all static cache variables for terms by using taxonomy_terms_static_reset().

What is Drupal

Drupal is one of the most popular CMS (content management system) around. One of the reasons is that with Drupal, editors and site administrators don't need a technical background to manage and insert content to a site. Possibilities for sites are endless.

Add an extra view mode to an entity

The extra view mode is added to the entity by using hook_entity_info_alter.

In this example the node entity is expanded so a hook_preprocess_hook theme function is used to add all available theme modes as template suggestions to the node. Templates like node--article--teaser.tpl.php and node--article--teaser-overview.tpl.php are now available.

Write your first Drupal 7 module

There are two files needed when building modules:

A .info file which stores metadata about the module to notify Drupal of the existance of a module and renders its information on the administration pages and a .module file where the PHP code is stored.

Remove the taxonomy description field Drupal 7

The description field from taxonomy terms is a property of the taxonomy term entity and can't be deleted. It isn't a field coming from the field module but its values are stored inside the taxonomy_term_data table. Use hook_form_id_alter(&form, &form_state, $form_id) to access the taxonomy term form. This hook is placed inside a custom module.

Pages

Subscribe to RSS - Novice