0

I have those menu elements declared in hook_menu function:

$items['submission/%/id/%'] = array(
    'title' => 'View submission',
    'title callback' => 'fr_form_view_submission_page_title',
    'title arguments' => array(3),
    'page arguments' => array(1, 3),
    'page callback' => 'fr_form_node_object_id',
    'access arguments' => array('content access'),
    'type' => MENU_NORMAL_ITEM,
    'weight' => 100,
  );

  $items['submission/%/id/%/view'] = array(
    'title' => 'View submission',
    'title callback' => 'fr_form_view_submission_page_title',
    'title arguments' => array(3),
    'type' => MENU_DEFAULT_LOCAL_TASK,
  );

  $items['submission/%/id/%/edit'] = array(
    'title' => 'Edit submission',
    'page arguments' => array(1, 3, 4),
    'page callback' => 'fr_form_node_object_id',
    'title callback' => 'fr_form_edit_submission_page_title',
    'title arguments' => array(3),
    'access arguments' => array('content access'),
    'type' => MENU_LOCAL_TASK,
    'weight' => 100,
  );

As you can see the first menu item has a fr_form_view_submission_page_title() function to set the title. And the function looks like this:

function fr_form_view_submission_page_title($id) {
  return t('View submission ID: @id', array('@id' => $id));
}

Second item makes the first one default.

Third menu item has a title callback function which looks like this:

function fr_form_edit_submission_page_title($id) {
  return t('Edit submission ID: @id', array('@id' => $id));
}

When I go to page /submission/10/id/1 I get the result. Two tabs next to each other with text on it:

first tab: View submission ID: 1
second tab: Edit submission ID: 1

And the page title is: View submission ID: 1

And if I go to the edit tab (/submission/10/id/1/edit) I get exacly the same, so:

first tab: View submission ID: 1
second tab: Edit submission ID: 1

And the page title is: View submission ID: 1

What I want to achive is to have tabs always signed:

first tab: View submission

second tab: Edit submission

And the page title depending on path, so for /submission/10/id/1 I should get: View submission ID: 1

And for /submission/10/id/1/edit I should get: Edit submission ID: 1

1
  • Hi, David. Hopefully someone else can confirm but I don't think it's currently possible to set a different page title using hook_menu(). You may have to drupal_set_title() inside your page callback instead, perhaps retrieving your arguments from $_GET['q']. Commented Aug 17, 2015 at 10:33

1 Answer 1

0

You can use single title callback by passing two arguments :

'title arguments' => array(3, 4),

and use same callback for both function :

function fr_form_view_submission_page_title($id, $type = 'view') {
  $type = ucfirst($type);
  return t('@type submission ID: @id', array('@type' => $type, '@id' => $id));
}

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.