2011-04-02 43 views

回答

2

我能夠通過使用下面的代碼來實現這一點。

$menu_block = array(
    'module' => 'menu', 
    'delta' => 'IDBLOCK', // the id of the block 
    'theme' => 'MYTHEME', // the current theme 
    'visibility' => 1, // it is displayed only on those pages listed in $block->pages. 
    'region' => 'menu', 
    'status' => 1, 
    'pages' => '', // display the menu only for these pages 
    ); 

drupal_write_record('block', $menu_block); 
2

drupal_write_record如果您想在更新掛鉤中使用,則不起作用。如果您正在更新或創建數據庫條目,您當然也可以使用db_update或db_insert。下面是一個示例更新:

<?php 
// find your block id, for me $bid = 38 
db_update('block') 
    ->fields(array(
    'module' => 'system', 
    'delta' => 'main-menu', // block delta, find in database or module that defines it 
    'theme' => 'mytheme', // theme to configure 
    'visibility' => BLOCK_VISIBILITY_NOTLISTED, // see drupal constants 
    'region' => 'main_menu', // region declared in theme 
    'status' => 1, 
    'pages' => '', 
    ) 
) 
    ->condition('bid', $bid, '=') 
    ->execute(); 
?> 

有關參數的更多詳細信息,請參閱hook_block_info api。

相關問題