You are here

创建一个drupal区块(3)

 

当如图9-5所示的区块配置表单被提交后,它将触发下一个$op,这就是save。你将使用它来保存表单字段的值。
 
function approval_block($op = 'list', $delta = 0, $edit = array()) {
    switch ($op) {
        case 'list':
            $blocks[0]['info'] = t('Pending comments');
            $blocks[0]['cache'] = BLOCK_NO_CACHE;
            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':
           variable_set('approval_block_num_posts',
              (int)$edit['approval_block_num_posts']);
           break;
    }
}

老葛的Drupal培训班 Think in Drupal

Drupal版本: