I am having problems getting a pager to display after a table in the block_view hook of a module
The code for the query is the following one.
$query = db_select('registry', 'r');
$query = $query->extend('PagerDefault')->extend('TableSort');
$query->limit(10)
->fields('r', array('name', 'type', 'filename','module','weight'));
$result = $query->execute();
I build and the table with no problem adding it to the content
Then I add the pager or rather I don't with the following code
$block['content'] .= theme('pager').'<br>mmm<br>';
the mmm bit was just there as a quick check to see what was happening.
I know that the extend needs to be assigned to a new variable and I believe that I am doing this.
Is there anything wrong I am doing?
This is the complete code of the module.
/**
* @file
* A block module that displays registry info.
*/
/**
* Implements hook_help.
*
* Displays help and module information.
*
* @param path
* Which path of the site we're using to display help
* @param arg
* Array that holds the current path as returned from arg() function
*/
function current_posts_help($path, $arg) {
switch ($path) {
case "admin/help#current_posts":
return '<p>' . t("Displays registry info for testing tables and pager") . '</p>';
break;
}
}
/**
* Implements hook_block_info().
*/
function current_posts_block_info() {
$blocks['current_posts'] = array(
'info' => t('Current posts'), //The name that will appear in the block list.
'cache' => DRUPAL_CACHE_PER_ROLE, //Default
);
return $blocks;
}
function current_posts_block_view($delta = '') {
switch($delta) {
case 'current_posts':
$block['subject'] = t('Modules list');
if(user_access('access content')) {
$query = db_select('registry', 'r');
$query = $query->extend('PagerDefault');
//$result = $query->limit(50)
$query->limit(10)
->fields('r', array('name', 'type', 'filename','module','weight'));
$result = $query->execute();
// Array to contain items for the block to render.
$rows = array();
// Iterate over the resultset.
foreach ($result as $node) {
$rows[] = array(
'name' => t($node->name),
'type' => t($node->type),
'filename' => t($node->filename),
'module' => t($node->filename),
);
}
// Table header.
$header = array(
'name' => t('Name'),
'type' => t('Type'),
'filename' => t('Filename'),
'module' => t('Module'),
);
$block['content'] = theme('table', array(
'header' => $header,
'rows' => $rows,
'id' => 'table-articles',
'class' => 'articles',)
);
$block['content'] .= theme('pager').'<br>mmm<br>';
}
return $block;
}
}
/**
* Implements hook_menu().
*/
function current_posts_menu() {
$items = array();
$items['admin/config/content/current_posts'] = array(
'title' => 'Current Registry',
'description' => 'Configuration for Current posts module',
'page callback' => 'drupal_get_form',
'page arguments' => array('current_posts_form'),
'access arguments' => array('access administration pages'),
'type' => MENU_NORMAL_ITEM,
);
return $items;
}
/**
* Page callback: Current posts settings
*
* @see current_posts_menu()
*/
function current_posts_form($form, &$form_state) {
$form['current_posts_max'] = array(
'#type' => 'textfield',
'#title' => t('Maximum number of posts'),
'#default_value' => variable_get('current_posts_max', 3),
'#size' => 2,
'#maxlength' => 2,
'#description' => t('The maximum number of links to display in the block.'),
'#required' => TRUE,
);
return system_settings_form($form);
}