You are here



function approval_block($op = 'list', $delta = 0, $edit = array()) {
    switch ($op) {
        case 'list':
            $blocks[0]['info'] = t('Pending comments');
            return $blocks;
        case 'configure':
            $form['approval_block_num_posts'] = array(
                '#type' => 'textfield',
                '#title' => t('Number of pending comments to display'),
                '#default_value' => variable_get('approval_block_num_posts', 5),
            return $form;
        case 'save':
        case 'view':
            if (user_access('administer comments')) {
               // Retrieve the number of pending comments to display that
               // we saved earlier in the 'save' op, defaulting to 5.
               $num_posts = variable_get('approval_block_num_posts', 5);
               // Query the database for unpublished comments.
               $result = db_query_range('SELECT c.* FROM {comments} c WHERE
               c.status = %d ORDER BY c.timestamp', COMMENT_NOT_PUBLISHED, 0,
               // Preserve our current location so user can return after editing.
               $destination = drupal_get_destination();
               $items = array();
               while ($comment = db_fetch_object($result)) {
                   $items[] = l($comment->subject, 'node/'. $comment->nid,
                      array('fragment' => 'comment-'. $comment->cid)) .' '.
                      l(t('[edit]'), 'comment/edit/'. $comment->cid,
                      array('query' => $destination));
               $block['subject'] = t('Pending comments');
               // We theme our array of links as an unordered list.
               $block['content'] = theme('item_list', $items);
            return $block;

老葛的Drupal培训班 Think in Drupal



官方勘误:    Page 213


The following line of code:
$blocks[0]['cache'] = BLOCK_NO_CACHE;

is missing from:

case 'list':
$blocks[0]['info'] = t('Pending comments');
return $blocks;


case 'list':
$blocks[0]['info'] = t('Pending comments');
$blocks[0]['cache'] = BLOCK_NO_CACHE;
return $blocks;

Description of the Error: 

The block cache setting is missing from the approval.module code example on page 213. Its is included in all other examples of approval.module code in the "Building a Block" section.