I am doing something wrong and am not able to find what.

I have defined the hook_menu for my module, add and delete are working fine, but edit and view are not. Is like are never being called.

function nutrition_menu()
  $items['admin/structure/ingredients'] = array(
    'title' => 'Manage Ingredients.',
    'description' => 'Manage Ingredients.',
    'access arguments' => array('administer ingredients'),

  $items['ingredient/%ingredient'] = array(
    'title callback' => 'ingredient_page_title',
    'title arguments' => array(1),
    'page callback' => 'ingredient_page_view',
    'page arguments' => array(1),
    'access arguments' => array('view ingredients'),
    'type' => MENU_CALLBACK,


  $items['ingredient/%ingredient/view'] = array(
    'title' => 'View',
    'weight' => -10,


  $items['ingredient/%ingredient/edit'] = array(
    'title' => 'Edit',
    'page callbacks' => 'ingredient_page_edit',
    'page arguments' => array(1),
    'access arguments' => array('update ingredients'),
    'weight' => 2,
    'type' => MENU_LOCAL_TASK,


  $items['ingredient/add'] = array(
    'title' => 'Add new Ingredient:',
    'page callback' => 'ingredient_add',
    'access arguments' => array('create ingredients'),
    'weight' => 1,
    'menu_name' => 'management',
    'file' => 'ingredient.pages.inc',

  $items['ingredient/%ingredient/delete'] = array(
    'title' => 'Delete',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('ingredient_delete_confirm',1),
    'access arguments' => array('delete ingredients'),
    'weight' => 1,
    'type' => MENU_LOCAL_TASK,
    'context' => MENU_CONTEXT_INLINE,


  return $items;

load functions

function ingredient_load( $iid = NULL, $reset = NULL)
  $iids = (isset($iid) ? array($iid) : array() );
  $conditions = array();
  $ingredient = ingredient_load_multiple($iids, $conditions, $reset);
  return $ingredient ? reset($ingredient) : FALSE;

function ingredient_load_multiple($iids=array(),$conditions=array(),$reset=FALSE)
  return entity_load('ingredient', $iids, $conditions, $reset);


function ingredient_page_view($ingredient,$view_mode='full')
  $ingredient->content = array();

  field_attach_prepare_view('ingredient', array($ingredient->iid=>$ingredient),$view_mode);
  $ingredient->content += field_attach_view('ingredient',$ingredient,$view_mode);

  return $ingredient->content;

function ingredient_page_edit($ingredient)

  drupal_set_title(t('Edit @name', array('@name' => $ingredient->name)), PASS_THROUGH);

  return drupal_get_form('ingredient_form',$ingredient);

Basically what I see is the two tabs ( View, Edit ) with no information bellow, the title isn't changing either.

Any idea?

  • What do you want to achieve? To me this looks like you're building an ingredient content type. If yes, almost all the code you show is not necessary. Have a look at the example module about how (drupal.org/project/examples) to build content types. There's even a good chance, that fields will do everything for you, which means you don't have to code anything. – BetaRide Jan 24 '12 at 19:03
  • I am creating a module ( entities included ) this is just a piece of code I copied and adapted from a book. Thanks for the advise though – Xavi Colomer Jan 24 '12 at 19:25

The 'edit' page probably isn't working because you've mis-spelled page callback (it's currently spelt page callbacks).

|improve this answer|||||
  • Thank you @Clive. The Only thing missing is that view is not showing anything. Thanks! – Xavi Colomer Jan 24 '12 at 19:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.