Skip to main content
improved formatting; edited tags; edited title
Source Link
avpaderno
  • 97.9k
  • 15
  • 164
  • 284

Custom Module & Blockmodule and block API

Here's the code for easy review: The first.info file:::


;$Id$

name = First
description = A first module.
package = Drupal 7 Development
core = 7.x
files[] = first.module

;dependencies[] = autoload
;php = 5.2
name = First
description = A first module.
package = Drupal 7 Development
core = 7.x
files[] = first.module

;dependencies[] = autoload
;php = 5.2

The first. module file::::


 t('A listing of all of the enabled modules.'),
    'cache' => DRUPAL_NO_CACHE,
  );

  return $blocks;
}

/**
 * Implements hook_block_view().
 */
function first_block_view($block_name = '') {
  if ($block_name == 'list_modules') {
    $list = module_list();

    $theme_args = array('items' => $list, 'type' => 'ol');
    $content = theme('item_list', $theme_args);

    $block = array(
      'subject' => t('Enabled Modules'),
      'content' => $content,
    );

    return $block;
  }
}
/**
 * @file
 * A module exemplifying Drupal coding practices and APIs.
 *
 * This module provides a block that lists all of the
 * installed modules. It illustrates coding standards,
 * practices, and API use for Drupal 7.
 */

/**
 * Implements hook_help().
 */
function first_help($path, $arg) {
  if ($path == 'admin/help#first') {
    return t('A demonstration module.');
  }
}

/**
 * Implements hook_block_info().
 */
function first_block_info() {
  $blocks = array();

  $blocks['list_modules'] = array(
    'info' => t('A listing of all of the enabled modules.'),
    'cache' => DRUPAL_NO_CACHE,
  );

  return $blocks;
}

/**
 * Implements hook_block_view().
 */
function first_block_view($block_name = '') {
  if ($block_name == 'list_modules') {
    $list = module_list();

    $theme_args = array('items' => $list, 'type' => 'ol');
    $content = theme('item_list', $theme_args);

    $block = array(
      'subject' => t('Enabled Modules'),
      'content' => $content,
    );

    return $block;
  }
}

Custom Module & Block API

Here's the code for easy review: The first.info file:::


;$Id$

name = First
description = A first module.
package = Drupal 7 Development
core = 7.x
files[] = first.module

;dependencies[] = autoload
;php = 5.2

The first. module file::::


 t('A listing of all of the enabled modules.'),
    'cache' => DRUPAL_NO_CACHE,
  );

  return $blocks;
}

/**
 * Implements hook_block_view().
 */
function first_block_view($block_name = '') {
  if ($block_name == 'list_modules') {
    $list = module_list();

    $theme_args = array('items' => $list, 'type' => 'ol');
    $content = theme('item_list', $theme_args);

    $block = array(
      'subject' => t('Enabled Modules'),
      'content' => $content,
    );

    return $block;
  }
}

Custom module and block API

name = First
description = A first module.
package = Drupal 7 Development
core = 7.x
files[] = first.module

;dependencies[] = autoload
;php = 5.2
/**
 * @file
 * A module exemplifying Drupal coding practices and APIs.
 *
 * This module provides a block that lists all of the
 * installed modules. It illustrates coding standards,
 * practices, and API use for Drupal 7.
 */

/**
 * Implements hook_help().
 */
function first_help($path, $arg) {
  if ($path == 'admin/help#first') {
    return t('A demonstration module.');
  }
}

/**
 * Implements hook_block_info().
 */
function first_block_info() {
  $blocks = array();

  $blocks['list_modules'] = array(
    'info' => t('A listing of all of the enabled modules.'),
    'cache' => DRUPAL_NO_CACHE,
  );

  return $blocks;
}

/**
 * Implements hook_block_view().
 */
function first_block_view($block_name = '') {
  if ($block_name == 'list_modules') {
    $list = module_list();

    $theme_args = array('items' => $list, 'type' => 'ol');
    $content = theme('item_list', $theme_args);

    $block = array(
      'subject' => t('Enabled Modules'),
      'content' => $content,
    );

    return $block;
  }
}
edited tags
Link
Chapabu
  • 13.9k
  • 2
  • 40
  • 58

Have followed all the steps at http://www.packtpub.com/comment/reply/7089 to create a custom module. 

I am able to create it and it is showing under the Modules and is getting enabled. However as the purpose of this module is to create a new block it is not doing so. Its not showing under the Structure/Blocks. Any reasons?

Here's the code for easy review: The first.info file:::

;$Id$

name = First description = A first module. package = Drupal 7 Development core = 7.x files[] = first.module

;dependencies[] = autoload ;php = 5.2


;$Id$

name = First
description = A first module.
package = Drupal 7 Development
core = 7.x
files[] = first.module

;dependencies[] = autoload
;php = 5.2

The first. module file::::

t('A listing of all of the enabled modules.'), 'cache' => DRUPAL_NO_CACHE, ); return $blocks; } /** * Implements hook_block_view(). */ function first_block_view($block_name = '') { if ($block_name == 'list_modules') { $list = module_list(); $theme_args = array('items' => $list, 'type' => 'ol'); $content = theme('item_list', $theme_args); $block = array( 'subject' => t('Enabled Modules'), 'content' => $content, ); return $block; } }

 t('A listing of all of the enabled modules.'),
    'cache' => DRUPAL_NO_CACHE,
  );

  return $blocks;
}

/**
 * Implements hook_block_view().
 */
function first_block_view($block_name = '') {
  if ($block_name == 'list_modules') {
    $list = module_list();

    $theme_args = array('items' => $list, 'type' => 'ol');
    $content = theme('item_list', $theme_args);

    $block = array(
      'subject' => t('Enabled Modules'),
      'content' => $content,
    );

    return $block;
  }
}

Have followed all the steps at http://www.packtpub.com/comment/reply/7089 to create a custom module. I am able to create it and it is showing under the Modules and is getting enabled. However as the purpose of this module is to create a new block it is not doing so. Its not showing under the Structure/Blocks. Any reasons?

Here's the code for easy review: The first.info file:::

;$Id$

name = First description = A first module. package = Drupal 7 Development core = 7.x files[] = first.module

;dependencies[] = autoload ;php = 5.2

The first. module file::::

t('A listing of all of the enabled modules.'), 'cache' => DRUPAL_NO_CACHE, ); return $blocks; } /** * Implements hook_block_view(). */ function first_block_view($block_name = '') { if ($block_name == 'list_modules') { $list = module_list(); $theme_args = array('items' => $list, 'type' => 'ol'); $content = theme('item_list', $theme_args); $block = array( 'subject' => t('Enabled Modules'), 'content' => $content, ); return $block; } }

Have followed all the steps at http://www.packtpub.com/comment/reply/7089 to create a custom module. 

I am able to create it and it is showing under the Modules and is getting enabled. However as the purpose of this module is to create a new block it is not doing so. Its not showing under the Structure/Blocks. Any reasons?

Here's the code for easy review: The first.info file:::


;$Id$

name = First
description = A first module.
package = Drupal 7 Development
core = 7.x
files[] = first.module

;dependencies[] = autoload
;php = 5.2

The first. module file::::


 t('A listing of all of the enabled modules.'),
    'cache' => DRUPAL_NO_CACHE,
  );

  return $blocks;
}

/**
 * Implements hook_block_view().
 */
function first_block_view($block_name = '') {
  if ($block_name == 'list_modules') {
    $list = module_list();

    $theme_args = array('items' => $list, 'type' => 'ol');
    $content = theme('item_list', $theme_args);

    $block = array(
      'subject' => t('Enabled Modules'),
      'content' => $content,
    );

    return $block;
  }
}
Source Link
why
  • 1.1k
  • 1
  • 17
  • 38
Loading