我想我找到了它。我只需要在我的配置中转到权限并在那里进行管理。
嗨,我做了这个模块,一切顺利。 我想如何让匿名用户在导航中看到Mijn bericht表单链接。并且还能够发布消息。我该怎么做呢?我在Drupal努力学习它的那个菜鸟,但它并不像我想象的那么容易。
这是我的模块页面:
<?php
/*
* Het module bestand van de module form_bericht.
*
*/
/*
*
* Implementatie van hook_permission.
* Deze methode gebruik ik om de juiste permissions te geven. Voor het gebruik van de form en het bekijken van de data.
*/
function form_bericht_permission() {
return array(
'submit form_bericht' => array(
'title' => t('submit form_bericht'),
'description' => t('Submit the form of form_bericht.'),
),
'acess form_bericht submissions' => array(
'title' => t('acess form_bericht submissions'),
'description' => t('acess the form_bericht submissions.'),
),
);
}
/*
* Implementatie van hook_menu()
*/
function form_bericht_menu() {
$items['form-bericht'] = array(
'title' => 'Mijn bericht form',
'type' => MENU_NORMAL_ITEM,
'access arguments' => array('submit form_bericht'),
'page callback' => 'drupal_get_form',
'page arguments' => array('form_bericht_form'),
);
$items['form-bericht-submissions'] = array(
'title' => 'Mijn bericht form submissions',
'type' => MENU_NORMAL_ITEM,
'access arguments' => array('acess form_bericht submissions'),
'page callback' => 'form_bericht_submissions',
);
return $items;
}
/*
* Het eigelijke form van form_feedback
*/
function form_bericht_form($form, &$form_state) {
$form['email_auteur'] = array(
'#type' => 'textfield',
'#title' => t('Uw email adres: '),
'#size' => 60,
'#maxlength' => 100,
'#required' => TRUE,
);
$form['bericht'] = array(
'#title' => t('Uw bericht: '),
'#type' => 'textarea',
'#description' => t('Enter some text...'),
'#default_value' => '',
'#required' => TRUE,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Voeg bericht toe.'),
);
return $form;
}
/*
* Validation handler voor de form van de module form_bericht.
*/
function form_bericht_form_validate($form, $form_state) {
// Deze if statement wordt gebruikt om te kijken of de email die de persoon heeft meegegeven wel een geldige email is.
if (!valid_email_address($form_state['values']['email_auteur'])) {
form_set_error('email_auteur', 'Gelieve een geldige email in te voeren');
return FALSE;
}
//check van het bericht zelf.
return TRUE;
}
/*
* De submit handler voor onze form.
* Van de module form_bericht
* Slaat het bericht op in de databank. In de tabel form_bericht.
*/
function form_bericht_form_submit($form, $form_state) {
$nid = db_insert('form_bericht')
->fields(array(
'bericht' => check_plain($form_state['values']['bericht']),
'email_auteur' => $form_state['values']['email_auteur'],
))
->execute();
drupal_set_message(t('Je bericht werd door gestuurd.'));
}
/*
* View the submissions of the form of form_bericht
* Berichten worden verwijderd eenmaal ze gelezen zijn.
*/
function form_bericht_submissions() {
$results = db_query("SELECT nid, bericht, email_auteur FROM {form_bericht}");
$header = array();
$rows = array();
if (count($results) > 1) {
$header = array(t('ID'), t('bericht'), t('email_auteur'));
foreach ($results AS $result) {
$rows[] = array(
$result->nid,
$result->bericht,
$result->email_auteur,
);
db_query("DELETE FROM {form_bericht} WHERE nid=" . $result->nid);
}
return theme('table', array('header' => $header, 'rows' => $rows));
}
drupal_set_message(t("Je hebt geen nieuwe berichten."), 'info');
return theme('table', array('header' => $header, 'rows' => $rows));
}
?>
答案 0 :(得分:1)
如果您需要控制您的权限,您可以使用(查看代码,并获得您想要的内容,因为我从我的模块中获取它。)
function moduleName_permission() {
return array(
'access download-page content' => array(
'title' => t('Access content for the Download units page'),// title on permission page
)
);
}
function custom_books_download_menu() {
$items['download-page'] = array(
'title' => 'Download',
'page callback' => 'custom_books_download_download_page',
'access arguments' => array('access download-page content'),
'type' => MENU_SUGGESTED_ITEM,
);
return $items;
}
这种方式将在admin-&gt; people-&gt;权限
中返回名称模块的权限选项您还可以使用另一种方式
'access arguments' => array('access content')
这种方式会授予所有用户访问权限的权限,有关此外观的更多信息请参阅Access Arguments
祝你好运