I made a module, and defined my custom entity there. I set the path for the administrative page using the following array.

'admin ui' => array(
  'path' => 'admin/structure/optimizations',

How can I get the edit path for one instance of my entity, for example admin/structure/optimizations/manage/2?

I don't think its a good idea to hard-code the path as with 'admin/structure/optimizations/manage' . $entity->id.
Is there any function to get the edit path for an entity?

2 Answers 2


You may want to take a look at hook_menu()

Here you can define paths and route variables to where they are needed.

For example:

function hook_menu() {
  $items['admin/structure/optimizations/manage/%'] = array(
      'title' => t('Your Page Title'),
      'page callback' => '_your_callback', // The callback that is building the page
      'page callback' => array(1), // This is the value from the % array key
      'access arguments' => array('administer users'), // A permission to require
      'type' => MENU_NORMAL_ITEM,

function _your_callback($val) {

  //Access the % from the URL defined in hook menu using $val.



You can use the 'uri callback' key in hook_entity_info

uri callback: The name of an implementation of callback_entity_info_uri().

That function can be used to return the URL to the entity.


  • That doesn't get you the edit path though...
    – Clive
    Mar 28, 2014 at 9:47
  • @Clive While not the normal case, depending on the entity usage, the entity uri can potentially be the edit URL, as in the case of commerce_product and commerce_product_uri ( e.g: admin/commerce/products/12 returns the edit form) Mar 28, 2014 at 10:09
  • I think the OP's after a generic solution to get the edit path for any entity (I don't think there's any such mechanism in core or the Entity module)
    – Clive
    Mar 28, 2014 at 10:13
  • @Clive, yeah, I'm not aware of a generic entity_edit_uri function. Another option would be hook_menu similar to what the node module does with node/%node/edit and defining the path that way. It would be more of the 'hardcoded' approach referred to by OP for the edit URL. Mar 28, 2014 at 10:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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