I cannot unregister some elements from a menu

Hi there,

I use the function elgg_unregister_menu() to delete some items from a menu. I try it on the owner_block menu, but although I catch the indexes of the elementes of that menu, no one disappear. I try then to add an item to the menu, with the next lines:

elgg_register_menu_item('owner_block', array(
        'name' => 'itemname',
        'text' => 'option1',
        'href' => ''

And then the menu show this option as 'option1'. Then I try to unregister it and it worked.

What am I doing wrong?

Some options that I have actually in the menu are

Group activity

Group blog

Group bookmarks

Is it probably that I get wrong the indexes? Thanks for your answers

  • The elgg_unregister_menu() function only works for static menu items. Anything that has to customize a URL based on the entity will need to be removed using a plugin hook as described here: http://reference.elgg.org/views_8php.html#ac2d475d3efbbec30603537013ac34e22

    You want to use the prepare, menu:<menu_name> hook.

  • Thanks for your help, Brett.

    I was look at some plugins, like bookmarks and file, and I saw thet there is a line like "elgg_register_plugin_hook_handler...", that is usually in start.php.

    For example, in the plugin file there's a line in start.php like this:

    // add a file link to owner blocks
    elgg_register_plugin_hook_handler('register', 'menu:owner_block', 'file_owner_block_menu');

    So in my plugin I use this:

    elgg_unregister_plugin_hook_handler('register', 'menu:owner_block', 'file_owner_block_menu');

    And then the item in the owner_block menu disappear. That's what I wanted to get.

    I search for the 'prepare' option use instead of 'register', but I don't find a useful information.

    Well, moreless I solved it.

    Now, I have other question, but it's probably less important.

    There are some items in the menus that have icons. In some plugins, when the callback is registered with the elgg_register_plugin_hook_handler function, when the content is executed, it loads the item, the url, and the icon. I'm interesting in create a new item menu with a customized icon.

    I know that icon is used as an entity, but althougth I look over the code of the file_owner_block_menu function, I cannot get how that icon is put into the  item menu.

    Any idea of how to get it? Thanks again

  • I recently finished writing a documentation for the menus. Take a look: http://learn.elgg.org/en/1.9/guides/menus.html

    It includes an example on how to add an icon as the menu link.

  • Thanks Juho.

    I'll have a look on it ;-)

Beginning Developers

Beginning Developers

This space is for newcomers, who wish to build a new plugin or to customize an existing one to their liking