我正在尝试 1)在块挂钩中实现挂钩菜单和 variable_set,并从用户那里请求和存储配置值,2)然后使用检索配置值和 3)在显示页面时使用主题挂钩将它们传递到模板中。
但是,我需要在第二步和第三步上稍加推动!
// ===================== file: my_module.php
function my_module_block($op = 'list', $delta = 0, $edit = array())
{
switch($op)
{
case 'list':
$blocks[0] = array(
'info' => t('Find Something'), // required value - this shows up in your list of blocks
'region' => 'left', // default region on the page
'weight' => 0, // position the block vertically within its column.
'visibility' => 1, // permit the block to be displayed for a given user.
'status' => TRUE, // enabled
);
return $blocks;
break;
// case configure
case 'configure':
// not used ?
// case save (save configuration values)
case 'save':
variable_set('my_module_text_bottom', $edit['my_module_text_bottom']);
variable_set('my_module_text_top', $edit['my_module_text_top']);
break;
}
}
function my_module_menu(){
$items = array();
// add menu items
$items['my_module'] = array(
// add a menu item here...
);
// administration setting - callback my_module_admin
$items['admin/settings/my_module'] = array(
'title' => 'Lookup on Something',
'description' => 'Description of my module settings page',
'page callback' => 'drupal_get_form',
'page arguments' => array('my_module_admin'),
'access arguments' => array('access administration pages'),
'type' => MENU_NORMAL_ITEM,
);
return $items;
}
// setup administrative default values (see: site configiration)
function my_module_admin() {
$form = array();
$form['my_module_text_top'] = array(
'#type' => 'textarea',
'#title' => t('Text of top of page'),
'#default_value' => variable_get('my_module_text_top', 'my_module_text_top: This is configurable text found in the module configuration.'),
'#size' => 1024,
'#maxlength' => 1024,
'#description' => t("text above the Find a Retailer block."),
'#required' => TRUE,
);
$form['my_module_text_bottom'] = array(
'#type' => 'textarea',
'#title' => t('Text at bottom of page'),
'#default_value' => variable_get('my_module_text_bottom', 'my_module_text_bottom: This is configurable text found in the module configuration.'),
'#size' => 1024,
'#maxlength' => 1024,
'#description' => t("text below the Find a Retailer block."),
'#required' => TRUE,
);
return system_settings_form($form);
}
// registering a theme
function my_module_theme(){
return array(
'my_module_show' => array(
'arguments' => array('content' => "hello"),
'template' => 'my_module_show'
),
);
}
// implementing a theme
function theme_my_module_show($content){
$output = '<ul>$content</ul>';
return $output;
}
function my_module(){
$output = '';
$variables = "";
$output .= theme('my_module_show', $variables);
return $output;
}
// ===================== file: my_module_show.tpl.php
print $text1;
print $text2;