我的函数内部似乎没有运行。
这里有什么想法吗?我已经阅读了多个 hook_menu() 问题,并且我的代码似乎格式正确。我尝试了许多不同的调用 $items 的方法。任何帮助将不胜感激。这似乎根本没有运行。我需要将数据库查询作为回调函数运行吗?如果是这样,我该怎么做?你会认为在现有菜单中添加一个链接会很容易......
function foodjournalmenuitem_menu() {
print "TEST";
global $user;
$items = array();
$query = db_select('node', 'n');
$query->condition('n.type', 'my_daily_food_page', '=')
->condition('n.uid', $user->uid, '=')
->fields('n', array('nid', 'title', 'uid', 'created'))
->range(0, 50)
->orderBy('n.created', 'DESC');
if ($query->execute()->fetchObject()) {
$result = $query->execute()->fetchObject();
if ($result->created) {
$created = $result->created;
$path = drupal_lookup_path('alias',"node/".$result->nid);
$now= time();
$hourDifference = round(($now- $created)/3600, 1);
// if ($hourDifference >= 9) {
// $output = l(t('Click Here to Create Today\'s Daily Food Page'), 'node/add/my-daily-food-page');
// print "<span id='add-foodpage'>".$output."</span>";
// } else {
// $link = "" . l("Click Here To Update Today's Daily Food Page", 'node/' . $results[0]->nid . '/edit') . " ";
// print "<span id='add-foodpage'>".$link."</span>";
// }
$createdDay = date("d", $created);
$createdMonth = date("m", $created);
$createdYear = date("Y", $created);
$createdHour = date("H", $created);
$nowDay = date("d", $now);
$nowMonth = date("m", $now);
$nowYear = date("Y", $now);
$nowHour = date("H", $now);
if ($createdDay != $nowDay || $createdMonth != $nowMonth || $createdYear != $nowYear) {
$items['node/add/my-daily-food-page'] = array(
'title' => 'Todays\'s Food Journal',
'weight' => 8,
'type' => MENU_NORMAL_ITEM,
'menu_name' => 'main-menu',
'access callback' => TRUE,
'access arguments' => array('access content'),
'page callback' => 'drupal_goto',
'page arguments' => array('node/add/my-daily-food-page'),
);
return $items;
}
else {
$items['node/' . $result->nid . '/edit'] = array(
'title' => 'Todays\'s Food Journal',
'weight' => 8,
'type' => MENU_NORMAL_ITEM,
'menu_name' => 'main-menu',
'access callback' => TRUE,
'access arguments' => array('access content'),
'page callback' => 'drupal_goto',
'page arguments' => array('node/' . $result->nid . '/edit'),
);
return $items;
}
}
else {
$items['node/add/my-daily-food-page'] = array(
'title' => 'Todays\'s Food Journal',
'weight' => 8,
'type' => MENU_NORMAL_ITEM,
'menu_name' => 'main-menu',
'access callback' => TRUE,
'access arguments' => array('access content'),
'page callback' => 'drupal_goto',
'page arguments' => array('node/add/my-daily-food-page'),
);
return $items;
}
}
else {
$items['node/add/my-daily-food-page'] = array(
'title' => 'Todays\'s Food Journal',
'weight' => 8,
'type' => MENU_NORMAL_ITEM,
'menu_name' => 'main-menu',
'access callback' => TRUE,
'access arguments' => array('access content'),
'page callback' => 'drupal_goto',
'page arguments' => array('node/add/my-daily-food-page'),
);
return $items;
}
}
?>