0

I have hook_menu with 3 pages they are defined by default as MENU_NORMAL_ITEMs and I see them from in main menu: enter image description here

$items['accounting'] = [
    'title' => 'Accounting',
    'page callback' => 'accounting_extras_unprocessed_page',
    'access arguments' => ['access accounting extras'],
    'file' => 'accounting.pages.inc',
    'type' => MENU_NORMAL_ITEM,
    'menu_name' => 'main-menu',
    'weight' => 10,
  ];

  $items['accounting/extras'] = [
    'title'   => 'Extras',
    'page callback' => 'accounting_extras_unprocessed_page',
    'access arguments' => ['access accounting extras'],
    'file' => 'accounting.pages.inc',
    'weight'  => 0,
    'menu_name' => 'main-menu',
  ];

  $items['accounting/report'] = [
    'title'            => 'Report',
    'page callback'    => 'drupal_get_form',
    'page arguments'   => ['accounting_report_form', 'report'],
    'access arguments' => ['access accounting report'],
    'file'             => 'forms/accounting_report.inc',
    'weight'           => 1,
    'menu_name'        => 'main-menu',
  ];

  $items['accounting/transfer'] = [
    'title'            => 'Internal transactions',
    'page callback'    => 'drupal_get_form',
    'page arguments'   => ['accounting_report_form', 'transfer'],
    'access arguments' => ['access accounting report'],
    'file'             => 'forms/accounting_report.inc',
    'weight'           => 2,
    'menu_name'        => 'main-menu',
  ];

But I also need to see them as MENU_LOCAL_TASK and if I add type = MENU_LOCAL_TASK then they disappear from menu and appear as local tasks enter image description here

What to do to see them in both places? Thank you.

1

You can use a bitwise operator for that, e.g.

MENU_LOCAL_TASK | MENU_NORMAL_ITEM

There's a real-world example in the core comment module (comment_menu()):

$items['admin/content/comment'] = array(
  'title' => 'Comments',
  'description' => 'List and edit site comments and the comment approval queue.',
  'page callback' => 'comment_admin',
  'access arguments' => array('administer comments'),
  'type' => MENU_LOCAL_TASK | MENU_NORMAL_ITEM,
  'file' => 'comment.admin.inc',
);
  • that solved my problem thank you, could you please explain or give a reference to these bitwise operators because it's something new for me. – serj Mar 19 at 13:55
  • It's a binary (bit masking) thing; details of PHP's implementation are here, but a good portion of languages have an equivalent – Clive Mar 19 at 14:10

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.