나는 최근에 비슷한 도전을했다. 클라이언트는 홈페이지에 표시 될 알림을 설정하는 방법이 필요했습니다. 귀하의 예제와 유사 : 과잉
솔루션처럼 보인다
1) 나는 편집자에게 바로 알림 콘텐츠 형식 만들기 블록
2
)를 편집 할 수있는 권한을 부여하고 싶지 않은를 만드는 것이 었습니다
1) 입력 경보 콘텐츠 형태를 만들고 드루팔 '변수'표 (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;
}