Allow elgg_echo in menus

Hello all. Currently I'm using menu_builder and I'd like to use multilingual menus. The easy way could be allowing elgg_echo as menu item titles, as this module (https://elgg.org/plugins/1226896) does, but don't know where to fit the lines that allow that, I mean, rendering an elgg_echo of the saved text instead of the saved text.

Is it that difficult? Could someone point me in the right direction? Anyway thanks to Jeroen Dalsem for this great module.

  • Finally I asked a colleage who is great at php and he kindly provided me with the solution, or workaround if you prefer. This works if, as the title of the menu item, you enter the languaje string code between square brackets [ ] like, for example [mymenu:activity]. For other types of delimiters you'll have to change the first if comparators. Tested and running in elgg 1.12.2 with menu_builder 2.0 downloaded from https://github.com/ColdTrick/menu_builder

    Override views/default/navigation/menu/elements/item.php in your module copying the original view to start with, and insert this code at line 36:

    if(substr(trim($item->getText()), 0, 1) =='[' && substr(trim($item->getText()), strlen(trim($item->getText()))-1, 1) ==']') {
        $del = array('[',']');
        $item->setText(elgg_echo( str_replace($del, array(''), trim($item->getText()) ) ) );
    }
    else {
        $pat = '@<a href=\'#\'>\[(.[^\>]*)]@ui';
        preg_match($pat, trim($item->getText()), $arr);
        if(isset($arr) && is_array($arr) && isset($arr[1])) {
            $del = array('[',']');
            $item->setText(
                 str_replace('' . $arr[0], '<a href=\'#\'>' . elgg_echo($arr[1]), $item->getText() )
                );
    
        }
    }

    Then include all your strings in all languajes you like, in your module.

    Regards

    Fran

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