Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
By ziobudda on
Hi all. I have created my module but I have problem with create the administation section.
I have these functions:
/**
* Implementation of hook_perm().
*/
function zbnews_perm() {
return array('create zbnews', 'edit own zbnews','administer zbnews');
}
/**
* Implementation of hook_access().
*/
function zbnews_access($op, $node) {
global $user;
if ($op == 'create') {
return user_access('create zbnews');
}
/*
if ($op == 'update' || $op == 'delete') {
if ((user_access('edit own zbnews') && ($user->uid == $node->uid)) || user_access('administer zbnews')) {
return TRUE;
}
}
*/
}
function zbnews_menu($may_cache) {
$items = array();
if ($may_cache) {
$items[] = array('path' => 'node/add/zbnews', 'title' => t('Aggiungi una notizia'),
'access' => user_access('create zbnews'));
}
$items[] = array(
'path' => 'zbnews/goto',
'title' => t('Pagina di redirect'),
'callback' => 'zbnews_goto',
'type' => MENU_CALLBACK,
'callback arguments' => $node ,
'access' => user_access('create zbnews'));
if (arg(0) == 'node' && is_numeric(arg(1))) {
$node = node_load(arg(1));
if ($node->nid) {
$items[] = array('path' => 'node/'. arg(1) .'/edit', 'title' => t('edit'),
'callback' => 'zbnews_form',
'access' => node_access('administer zbnews', $node),
'weight' => 1,
'type' => MENU_LOCAL_TASK);
}
}
}
function zbnews_form(&$node) {
//print_r($node);
if ($node->uid == 0) {
$form['name'] = array('#type' => 'textfield', '#title' => t('Il tuo nome'), '#required' => TRUE, '#default_value' =>
$node->name, '#weight' => -10);
$form['mail'] = array('#type' => 'textfield', '#title' => t('La tua email'), '#required' => FALSE, '#default_value'
=> $node->mail, '#weight' => -9);
}
$form['title'] = array('#type' => 'textfield', '#title' => t('Titolo notizia'), '#required' => TRUE, '#default_value' => $
node->title, '#weight' => -8);
$form['body_filter']['body'] = array('#type' => 'textarea', '#title' => t('Notizia'), '#default_value' => $node->body, '#r
ows' => 20, '#required' => TRUE, '#weight' => -7);
$form['url'] = array('#type' => 'textfield', '#title' => t('Url'), '#required' => TRUE, '#default_value' => $node->url, '#
weight' => 10);
$form['body_filter']['format'] = filter_form($node->format);
$form['format'] = array('#default_value' => 4);
//print_r($form);
for ($i=0;$i < count($form['body_filter']['format']); $i++)
{
if ($form['body_filter']['format'][$i]['#title'] != 'Notizie')
unset($form['body_filter']['format'][$i]);
else {
$form['body_filter']['format'][$i]['#default_value'] = $i;
$form['body_filter']['format']['#default_value']= $i;
}
}
//print_r($form);
return $form;
}
Now, when I go to url "?q=node/68/edit" (68 is a zbnews node) the only thing that I receive is the word Array() (into my theme), but not the form (the same form that I use for add zbnews node). I know that zbnews_form() function is called (debug).
Where is my error ?
TNX.