最近、同様の課題がありました。クライアントは、ホームページに表示されるアラートを設定する方法を必要としていました。あなたの例に似ています:
1) 編集者にブロックを編集する許可を与えたくなかった
2) アラートのためだけにコンテンツ タイプを作成するのはやり過ぎに思えます
解決策は、次のことを行う単純なモジュールを作成することでした。
1) アラートの内容を入力するフォームを作成し、その内容を Drupal の「変数」テーブルに格納します (hook_admin())
2) フォームを保持するための管理ページを作成します (hook_menu())
3) アラートを編集できる役割に割り当てる新しい許可を定義します (hook_perm())
4) 変数テーブルに格納された値を page.tpl に送信します (hook_preprocess_page())
完全なモジュール ファイル:
/**
* Build the administration form which collects the following and store the values in the vars table:
*
* @toggle - whether or not an alert is active
* @severity - Severity of the alert (low or high)
* @title - The title of the Alert (usualy "Alert")
* @content - Content to display on the homepage
* @node - The associated Alert Node. The Read More link on the homepage will link to this node
*
*/
function alerts_admin() {
$form = array();
$form['alerts_description'] = array (
'#value' => '<p>Use this page to set an Alert. If the "Turn On Alert" checkbox is checked, a blue or red banner (depending on the Alert Severity) will be displayed on the homepage containing the copy defined here.',
);
$form['alerts_toggle'] = array (
'#type' => 'checkbox',
'#title' => 'Turn Alert On.',
'#default_value' => variable_get('alerts_toggle', 0),
'#size' => 2,
'#maxlength' => 2,
'#description' => t("Select this checkbox to turn on the Homepage Alert."),
'#required' => TRUE,
);
$form['alerts_severity'] = array (
'#type' => 'select',
'#title' => 'Severity',
'#options' => array (
'low' => 'Low Severity - Blue',
'high' => 'High Severity - Red',
),
'#default_value' => variable_get('alerts_severity', 'low'),
'#required' => TRUE,
);
$form['alerts_title'] = array (
'#type' => 'textfield',
'#title' => 'Title',
'#description' => 'Enter the title of the Alert (e.g. "Alert").',
'#default_value' => variable_get('alerts_title', 'Alert'),
'#required' => TRUE,
);
$form['alerts_content'] = array (
'#type' => 'textarea',
'#title' => 'Content',
'#default_value' => variable_get('alerts_content', 'Example alert content'),
'#required' => TRUE,
);
//Build the options list for the associated node select list. We're just pulling a list of all the template6 content of the site.
$result = db_query("SELECT nid, title FROM {node} WHERE type = 'template6'");
$i=0;
while ($row = db_fetch_array($result)) {
$key = $row['nid'];
$value = $row['title'];
$options[$key] = $value;
}
$form['alerts_node'] = array (
'#type' => 'select',
'#title' => 'Associated Article',
'#options' => $options,
'#description' => 'The "Read More" link at the end of the alert will link to this Article.<p><strong>You must create the node first before you can select it here.</strong> ' . l('Click here', 'node/add/template6') . ' to create an article.',
'#default_value' => variable_get('alerts_node', ''),
'#required' => TRUE,
);
return system_settings_form($form);
}
/**
* Create the page for and link to the form
*/
function alerts_menu() {
$items = array();
$items['admin/settings/alerts'] = array(
'title' => 'Site Alert Settings',
'description' => 'Toggle alerts on/off and configure the title and contents',
'page callback' => 'drupal_get_form',
'page arguments' => array('alerts_admin'),
'access arguments' => array('administer alerts settings'),
'type' => MENU_NORMAL_ITEM,
);
return $items;
}
/**
* Create a new perm to administer Site Alerts
*
* This permission can be given to any role
*/
function alerts_perm() {
return array('administer alerts settings');
}
function alerts_preprocess_page(&$vars) {
$alert = 0;
$banner_classes = array();
$banner_classes[] = 'banner';
if (variable_get('alerts_toggle', '0') == '1') {
$banner_classes[] = 'alert';
$alert = 1;
$alert_content = array(
'title' => variable_get('alerts_title', 'Alert'),
'content' =>variable_get('alerts_content', 'Example alert content'),
'node' => variable_get('alerts_node', ''),
);
if (variable_get('alerts_severity', 'low') == 'high') {
$banner_classes[] = 'high';
}
else $banner_classes[] = 'low';
}
$banner_classes = implode(' ', $banner_classes);
$vars['banner_classes'] = $banner_classes;
$vars['alert'] = $alert;
$vars['alert_content'] = $alert_content;
}