0

I would like to add an hook_menu item and generate its expandable subitems under ubercart's 'admin/store/' path.

For now I have:

function activit_menu() {

  $items['admin/store/products-fabrics'] = array(
      'title' => 'Látky produktov',
      'access arguments' => array('access administration menu'),
      'type' => MENU_NORMAL_ITEM,
  );

      $items = array_merge($items, activit_generate_products_fabrics_menu_items());

    }



function activit_generate_products_fabrics_menu_items() {

  $products = activit_get_products_with_fabrics();

  $items = array();

  foreach($products as $product) {

    $items['admin/store/products-fabrics/'.$product['nid']] = array(
        'title' => $product['title'],
        'access arguments' => array('access administration menu'),
        'file' => 'd_forms.inc',
        'page callback' => 'drupal_get_form',
        'page arguments' => array('activit_eshop_fabrics_of_products_form'),
        'type' => MENU_LOCAL_ACTION
    );

  }

  return $items;

}

But this code will create both 'products-fabrics' item and all its subitems at the same level in administration menu and 'admin/store/products-fabrics' item is not expendable. After clicking at 'products-fabrics' item you will see the same andimistration page as aftre clicking at 'admin/store' plus the subitems links at the top oft he page. I can hide this page with css an let only the subitems to be visible. But I need to create expandable 'admin/store/products-fabrics' item in order to be able to click directly at 'admin/store/products-fabrics/subitem'.

I was trying all the possible item types but no success. Is there something I am missing?

1

I think the MENU_LOCAL_ACTION type for your sub-menus is not the good choice.

The Menu item types documentation tell us :

MENU_LOCAL_ACTION : Menu type -- An action specific to the parent, usually rendered as a link.

If you want to have a menu with sub-menus, you need to also define a page call back for it. You can use the system_admin_menu_block_page, witch display a bloc with all the sub-menus links.

// Main menu link
$items['admin/store/products-fabrics'] = array(
    'title' => 'Látky produktov',
    'page callback' => 'system_admin_menu_block_page',
    'access arguments' => array('access administration pages'),
    'file' => 'system.admin.inc',
    'file path' => drupal_get_path('module', 'system'),
    'type' => MENU_NORMAL_ITEM,
);

// Sub menu links
$items['admin/store/products-fabrics/'.$product['nid']] = array(
    'title' => $product['title'],
    'access arguments' => array('access administration menu'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('activit_eshop_fabrics_of_products_form'),
    'type' => MENU_NORMAL_ITEM,
    'file' => 'd_forms.inc',
);
  • No, it does not work. Subitems are still directly in 'admin/store/subitem' and 'admin/store/products-fabrics' is not even displayed. – Incredible Aug 3 '16 at 7:32
  • Maybe you have to disable your module, clear the cash, and enable your module again. It's append to me that modifications on a menu structure are not taken by Drupal when the module is already installed... – TytooF Aug 3 '16 at 8:10
  • After some changes and clearing cache multiple times it started to work. Then I changed the code back to your original form as you've posted and now it works. Seems like drupal has some problems clearing cahce for admin menu. Thanks. – Incredible Aug 3 '16 at 8:17

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.