hook_menu module issues what am i doing wrong?

82 Views Asked by At

Nothing inside my function seems to run.

Any ideas here? I havve read multiple hook_menu() questions and my code seems to be formatted properly. I have tried a number of different ways of invoking $items. Any help would be greatly appreciated. This doesnt seem to run at all. Do i need to run the DB query as a callback function? and if so how do i do that? you'd think just adding a link in an existing menu would be easy....

 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;
  }
}
?>
1

There are 1 best solutions below

1
On

you can use error_log and see output in httpd log file .

or you can use drupal's watchdog and see output under admin/reports/dblog , but you also need make sure module "database logging" is enabled .

i don't see where you use the value of drupal_lookup_path .

also i recommend changing this code :

if ($query->execute()->fetchObject()) {
 $result = $query->execute()->fetchObject();

to :

$result = $query->execute()->fetchObject();
if ($result) {