Jump to content

Menu Builder


kongondo

Recommended Posts

Update: Menu Builder Version 0.1.6.

Changelog

  1. Fixed a JS issue that stopped 'select all' checkbox from working in Menu Builder dashboard
  2. Fixed InputfieldMarkup issue that prevented HTML in description not to be properly rendered. Thanks @Jonathan Lahijani and @Michael van Laar
Menu Builder is now PW2.8 + PW3.x compatible! (first one of mine off the blocks!)
  • Like 4
Link to comment
Share on other sites

  • 1 month later...

Hi,

Great module - it's just what I needed!

However, I'm encountering a weird issue with some menu item titles.

If a menu item title contains an apostrophe/single-quote, the characters following (and including) the apostrophe are removed after saving the menu.

For example, the title "What's On" becomes "What".

It's ok if it is the initial save after adding that menu item, the apostrophed title is saved to the db, but it is subsequent saves that remove it.

It appears the characters are stripped when the title is displayed in Menu Builder's menu item editor widget.

Currently, the work around is to just retype each menu item that gets stripped before saving each time.

Using:
Menu Builder:  ver. 0.1.6
Processwire:     ver. 3.0.47

  • Like 2
Link to comment
Share on other sites

13 minutes ago, kongondo said:

Update: Menu Builder Version 0.1.7.

Changelog

  1. Fixed a bug that caused titles of menu items with apostrophes not to display properly in menu settings. Thanks @LMD
  2. Code cleanup and refactoring.

Gosh that was quick. Works a charm. Thanks!

  • Like 1
Link to comment
Share on other sites

Hello,

I recently installed MB on my multi-language's website in progress. I'm quite sure it was working in both languages. But since couple of days, I noticed this error

 

Exception: No menu items found! Confirm that such a menu exists and that it has menu items. (in /multimedia/sites/dev-wire/site/assets/cache/FileCompiler/site/modules/MarkupMenuBuilder/MarkupMenuBuilder.module line 961)

#0 /multimedia/sites/dev-wire/site/assets/cache/FileCompiler/site/modules/MarkupMenuBuilder/MarkupMenuBuilder.module(88): MarkupMenuBuilder->throwError()
#1 /multimedia/sites/dev-wire/site/templates/_main.php(194): MarkupMenuBuilder->render('main', Array)
#2 /multimedia/sites/dev-wire/wire/core/TemplateFile.php(276): require('/multimedia/sit...')
#3 /multimedia/sites/dev-wire/wire/core/Wire.php(374): ProcessWire\TemplateFile->___render()
#4 /multimedia/sites/dev-wire/wire/core/WireHooks.php(698): ProcessWire\Wire->_callMethod('___render', Array)
#5 /multimedia/sites/dev-wire/wire/core/Wire.php(402): ProcessWire\WireHooks->runHooks(Object(ProcessWire\TemplateFile), 'render', Array)
#6 /multimedia/sites/dev-wire/wire/modules/PageRender.module(514): ProcessWire\Wire->__call('render', Array)
#7 /multimedia/sites/dev-wire/wire/modules/PageRender.module(514): ProcessWire\TemplateFile->render()
#8 [internal function]: ProcessWire\PageRender->___renderPage(Object(ProcessWire\HookEvent))
#9 /multimedia/sites/dev-wire/wire/core/Wire.php(376): call_user_func_array(Array, Array)
#10 /multimedia/sites/dev-wire/wire/core/WireHooks.php(698): ProcessWire\Wire->_callMethod('___renderPage', Array)
#11 /multimedia/sites/dev-wire/wire/core/Wire.php(402): ProcessWire\WireHooks->runHooks(Object(ProcessWire\PageRender), 'renderPage', Array)
#12 /multimedia/sites/dev-wire/wire/core/WireHooks.php(782): ProcessWire\Wire->__call('renderPage', Array)
#13 /multimedia/sites/dev-wire/wire/core/WireHooks.php(782): ProcessWire\PageRender->renderPage(Object(ProcessWire\HookEvent))
#14 /multimedia/sites/dev-wire/wire/core/Wire.php(402): ProcessWire\WireHooks->runHooks(Object(ProcessWire\Page), 'render', Array)
#15 /multimedia/sites/dev-wire/wire/modules/Process/ProcessPageView.module(205): ProcessWire\Wire->__call('render', Array)
#16 /multimedia/sites/dev-wire/wire/modules/Process/ProcessPageView.module(205): ProcessWire\Page->render()
#17 [internal function]: ProcessWire\ProcessPageView->___execute(true)
#18 /multimedia/sites/dev-wire/wire/core/Wire.php(376): call_user_func_array(Array, Array)
#19 /multimedia/sites/dev-wire/wire/core/WireHooks.php(698): ProcessWire\Wire->_callMethod('___execute', Array)
#20 /multimedia/sites/dev-wire/wire/core/Wire.php(402): ProcessWire\WireHooks->runHooks(Object(ProcessWire\ProcessPageView), 'execute', Array)
#21 /multimedia/sites/dev-wire/index.php(55): ProcessWire\Wire->__call('execute', Array)
#22 /multimedia/sites/dev-wire/index.php(55): ProcessWire\ProcessPageView->execute(true)
#23 {main}

I'm currently running PW 3.0.50, but I'm unable to say what version it was when I previously installed.

I have 2 menus, but removing one or the other give the same error.

I call my menu by

    $options = array(
                        'wrapper_list_type' => 'ul',//ul, ol, nav, div, etc.
                        'menu_css_class' => 'topnav',//a CSS Class for the menu
                        'current_class' => 'active',
                            );
                            
                            
                            $menu = $modules->get('MarkupMenuBuilder');//Load the module. $menu is an example
                            echo $menu->render('main', $options);
                            

Do I doing something wrong?

Link to comment
Share on other sites

@mel47,

Please see this note on how to call a menu in a multi-lingual environment:

Quote

....The first argument is not optional and can be a Page object, a title, name or id of a menu or an array of menu items returned from a menu's menu_items field. Note that for multilingual environments, you cannot pass the method a title or a name; only the other three choices will work

If that doesn't resolve your issue, try refreshing your file compiler cache.

  • Like 2
Link to comment
Share on other sites

1 hour ago, kongondo said:

@mel47,

Please see this note on how to call a menu in a multi-lingual environment:

If that doesn't resolve your issue, try refreshing your file compiler cache.

Oh, my, my... I read it but it appears I didn't completely understood...

So solve my problem by replace with

$menu = $modules->get('MarkupMenuBuilder');//Load the module. $menu is an example
$m = $pages->get(2359);
echo $menu->render($m, $options);

 

Link to comment
Share on other sites

Hello, me again.

I've encountered another issue with Menu Builder.

This time it's related to HTML in the titles. I wanted to add FontAwesome icons to a menu, so enabled "Allow HTML in menu items title" in the settings for the menu.

I then added the FontAwesome code to the title field, like this:

pw-menubuilder-htmlprob01.jpg

When I saved the menu, it went weird and broke the editor widget (n.b. it's the same outcome using either single or double-quoted attributes):
pw-menubuilder-htmlprob02.jpg

Like the previous issue, the title does save to the DB (and when I looked at a frontend page, it showed the icon as it should), but when I tried to save the page again, the broken menu item completely disappeared (is not saved to the DB at all) and I had to add it again.

I think the menu editor widget doesn't like the HTML attributes, because it works fine with plain HTML elements without attributes.

Current Workaround:

Add a CSS class to the list item wrapper and manually add the FontAwesome icon in the site stylesheet.

Using:

Processwire:   ver 3.0.50
MenuBuilder: ver 0.1.7
 

 

Link to comment
Share on other sites

@LMD. Thanks for reporting. I haven't been able to find a suitable solution for this. The issue is the quotes are tripping up the input value. Have a look at the markup in page source; you will see class="" is output but the HTML breaks since we have something like value="<i class="fa fa-home">". For now (and for any complex menus), I suggest you use the approach posted here, whereby you will have total control over your menu items' structure and styling. 

Edited by kongondo
Link to comment
Share on other sites

@kongondo Thanks, I  got the menu working with a custom menu builder functions.

I couldn't help myself from digging around the in the the module code, though :).  I think I've found what seems to be a fairly simple solution to the quoted attributes breaking the form output.

In ProcessMenuBuilder.module, on line num. 1111:

https://github.com/kongondo/MenuBuilder/blob/bfc032cb3a07b65e732469b16b5286563bd709e9/ProcessMenuBuilder.module#L1111

Change:

<input type="text" value="' . $title . '" name="item_title[' . $id . ']" class="menu_settings" id="item_title' . $id . '">

To:

<input type="text" value="' . htmlentities($title) . '" name="item_title[' . $id . ']" class="menu_settings" id="item_title' . $id . '">

The htmlentities() function deals with the issue of quotes breaking the form input.

I've tested it on my site and it seems to be working just fine. The icons display in the front-end and the admin widget item label, and the code displays in the item's title edit field after being saved.

I don't know if I've missed anything though?

 

  • Like 2
Link to comment
Share on other sites

hello friends,

I have few children pages under a parent page.  i want to show that children page under two parents page in Main menu as well as in breadcrumbs.

With the help of menu builder main menu show same childern page under both the parents, but Breadcrumbs follow the page tree structure.

how can i get the expected result?

thank you.

Link to comment
Share on other sites

20 minutes ago, Sahil said:

I have few children pages under a parent page.  i want to show that children page under two parents page in Main menu as well as in breadcrumbs.

With the help of menu builder main menu show same childern page under both the parents, but Breadcrumbs follow the page tree structure.

how can i get the expected result?

I'll have to study this first. It's been a while since I developed the Breadcrumb component of Menu Builder :).

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...

Love the module! I was wondering if there was a way to add Schema.org markup support for the menus? If you look at "Site Navigation Schema Markup" on this site, you'll see that there is markup that should be added to get menu pages to show up with Google results. I would like to take advantage of this. Given the simplicity of the markup, I feel if it were to be put into this module, that it would make sense to enable with a checkbox on each separate menu created. (So I would enable on the "main" menu, but not the menu on the footer, if that makes sense.) Thanks!

EDIT:
I ended up hand-coding it into MarkupMenuBuilder.module at lines 367 and 368, which is good and achieves the proper result (and validation) but unfortunately creates 2 schema menus...there is a menu on top and one at the footer. I only want one schema menu, which is the longer one in the footer. I knew going in that it would likely do that, but it's certainly preferable that it doesn't. Also, when the module gets updated, it will wipe that out and it'd have to be done again. If this could be built in that would be great. BTW, I'll attach my code below (and my neurosis prefers double quotes in rendered HTML rather than single ;))...
 

if(!$iTag) $out .= "\n\t<a{$itemCSSID}{$class}{$newtab} href=\"{$m->url}\" itemprop=\"url\">{$m->title}</a>";
else $out .= "\n\t<{$iTag}{$itemCSSID}{$class} itemprop=\"name\">\n\t\t<a{$newtab} href=\"{$m->url}\" itemprop=\"url\">{$m->title}</a>";

 

Edited by Standard Forge
Hand coded part of my request
Link to comment
Share on other sites

@Standard Forge, Glad you find the module useful :).

On 17/02/2017 at 11:24 PM, Standard Forge said:

I ended up hand-coding it into MarkupMenuBuilder.module at lines 367 and 368, which is good and achieves the proper result (and validation) but

 As you point out, that's a bad idea :P. For complex or custom menus, there's a better way to achieve the result you want. I decided not to add any more features such as these to MenuBuilder (including "Bootstrap does this or that"...sort of requests). Instead, since a while back, Menu Builder now provides an API that will return your menu items allowing you greater control over their output. This is done via the method getMenuItems(). Please find detailed examples in this post. Grab one and edit it to suit your needs. Let us know how you get along.

Link to comment
Share on other sites


@Standard Forge, if you just want to make one or two minor changes to a rendered menu without having to build all the markup yourself (using getMenuItems()), you can do a quick str_replace.

Example:

$menu = $modules->get('MarkupMenuBuilder');

// cache the rendered menu
$schema_menu = $menu->render('my-menu-name');

// alter the rendered menu to your desire
$schema_menu = str_replace('<li ', '<li itemprop="name" ', $schema_menu);
$schema_menu = str_replace('<a ', '<a itemprop="url" ', $schema_menu);

// output the altered menu
echo $schema_menu;

Quick and dirty, I know. But if you are using delayed output anyway, it’s just one or two lines of code.

  • Like 1
Link to comment
Share on other sites

Hi, 

I don't want to list pages that aren't listable by the current user in the menu. I fixt it by adding an if statement on line 192 of MarkupMenuBuilder.module:

if($this->wire('pages')->get($m->pagesID)->listable()){
	$menu->add($m);
}

Is there a better way to do this? In a hook or a setting that I have missed? :)

Link to comment
Share on other sites

2 hours ago, Peejay said:

I don't want to list pages that aren't listable by the current user in the menu

Cool idea :).

2 hours ago, Peejay said:

Is there a better way to do this?

Yes; please file a feature request, thanks.

2 hours ago, Peejay said:

In a hook or a setting that I have missed?

No need for a hook. We can simply pass an option [which I'll create] to render(). However, this will not be as straightforward as it looks. What if that unlistable menu item has children, especially ones that are custom menus? We can't leave them parentless. They will have to be removed. Such a potential situation won't always be apparent at the editing stage; editors could unknowingly create a hierarchy that will break if the option to not list menu items is applied. Please file a request and I'll have a think.

  • Like 2
Link to comment
Share on other sites

  • 4 weeks later...

Glad you like the module @cjx2240

16 minutes ago, cjx2240 said:

Any plans for an enable/disable option on a menu item?

Do you mean if disabled menu item does not show in the frontend? What's the use case? Why not just not add that menu item? 

 

16 minutes ago, cjx2240 said:

Maybe a way to change a menu from one type to another?

I don't follow. Please explain.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...