Jump to content
kongondo

Menu Builder

Recommended Posts

Hey @kongondo I just recently came across this module in a existing PW project I had to take over. I knew about it's existence but never tried it myself. Great and useful features, thanks!

 

  • Like 1

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.
  • Like 2

Share this post


Link to post
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

Share this post


Link to post
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?

Share this post


Link to post
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

Share this post


Link to post
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);

 

Share this post


Link to post
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
 

 

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Welcome to the forums @Sahil. I have moved your topic to 'General Support'. If however, you are referring to the module Menu Builder, I will move your topic to its support forum and answer you question there. Please confirm.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
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.

Share this post


Link to post
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

Share this post


Link to post
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? :)

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Great module.

Any plans for an enable/disable option on a menu item? Maybe a way to change a menu from one type to another? I feel like this would make it more useable by an end-user.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By gebeer
      I am happy to present my new fieldtype FieldtypeImageFromPage. It is made up of 2 modules:
      Fieldtype Image Reference From Another Page is a Fieldtype that stores a reference to a single image from another page. The image can be selected with the associated Inputfield.
      Inputfield Select Image From Page is an Inputfield to select a single image from images on a predefined page and it's children.
      And there also is a helper module that takes care of cleanup tasks.
      This module evolved out of a discussion about my other Module FieldtypeImagePicker.  It caters for use cases where a set of images is being reused multiple times across a site. With this fieldtype these images can be administered through a chosen page. All images uploaded to that page will be available in the inputfield.
      When to use ?
      Let editors choose an image from a set of images that is being used site-wide. Ideal for images that are being re-used across the site.
      Suited for images that are used on multiple pages throughout the site (e.g. icons).
      Other than the native ProcessWire images field, the images here are not stored per page. Only references to images on another page are stored. This has several advantages:
      one central place to organize images when images change, you only have to update them in one place. All references will be updated, too. (Provided the name of the image that has changed stays the same) Features
      Images can be manipulated like native ProcessWire images (resizing, cropping etc.) Image names are fully searchable through the API Accidental image deletion is prevented. When you want to delete an image from one of the pages that hold your site-wide images, the module searches all pages that use that image. If any page contains a reference to the image you are trying to delete, deletion will be prevented. You will get an error message to help you edit those pages and remove references there before you can finally delete the image. How to install and setup
      Download and install this module like any other modules in ProcessWire Create a page in the page tree that will hold your images. This page's template must have an images field Upload some images to the page you created in step 2 Create a new field. As type choose 'Image Reference From Another Page'. Save the field. In 'Details' Tab of the field choose the page you created in step 2 Click Save button Choose the images field name for the field that holds your images (on page template from step 2) Click Save button again Choose whether you want to include child pages of page from step 2 to supply images Add the field to any template You are now ready to use the field View of the inputfield on the page edit screen:

      View of the field settings

      The module can be installed from this github repo. Some more info in the README there, too.
      In my tests it was fairly stable. After receiving your valued feedback, I will eventually add it to the modules directory.
      My ideas for further improvement:
      - add ajax loading of thumbnails
      Happy to hear your feedback!
       
    • By gebeer
      Although the PW backend is really intuitive, ever so often my clients need some assistance. Be it they are not so tech savvy or they are not working in the backend often.
      For those cases it is nice to make some help videos available to editors. This is what this module does.
      ProcessHelpVideos Module
      A Process module to display help videos for the ProcessWire CMS. It can be used to make help videos (screencasts) available to content editors.
      This module adds a 'Help Videos" section to the ProcessWire backend. The help videos are accessible through an automatically created page in the Admin page tree. You can add your help videos as pages in the page tree. The module adds a hidden page to the page tree that acts as parent page for the help video pages. All necessary fields and templates will be installed automatically. If there are already a CKEditor field and/or a file field for mp4 files installed in the system, the module will use those. Otherwise it will create the necessary fields. Also the necessary templates for the parent help videos page and it's children are created on module install. The module installs a permission process-helpvideos. Every user role that should have access to the help video section, needs this permission. I use the help video approach on quite a few production sites. It is stable so far and well received by site owners/editors. Up until now I installed required fields, templates and pages manually and then added the module. Now I added all this logic to the install method of the module and it should be ready to share.
      The module and further description on how to use it is available on github: https://github.com/gebeer/ProcessHelpVideos
      If you like to give it a try, I am happy to receive your comments/suggestions here.
    • By Robin S
      A module created in response to the topic here:
      Page List Select Multiple Quickly
      Modifies PageListSelectMultiple to allow you to select multiple pages without the tree closing every time you select a page.
      The screencast says it all:

       
      https://github.com/Toutouwai/PageListSelectMultipleQuickly
      https://modules.processwire.com/modules/page-list-select-multiple-quickly/
    • By gebeer
      Hello all,
      sharing my new module FieldtypeImagePicker. It provides a configurable input field for choosing any type of image from a predefined folder.
      The need for it came up because a client had a custom SVG icon set and I wanted the editors to be able to choose an icon in the page editor.
      It can also be used to offer a choice of images that are used site-wide without having to upload them to individual pages.
      There are no image manipulation methods like with the native PW image field.
      Module and full description can be found on github https://github.com/gebeer/FieldtypeImagePicker
      Kudos to @Martijn Geerts. I used his module FieldTypeSelectFile as a base to build upon.
      Here's how the input field looks like in the page editor:

      Hope it can be of use to someone.
      If you like to give it a try, I'm happy to hear your comments or suggestions for improvement. Eventually this will go in the module directory soon, too.
    • By bernhard
      @Sergio asked about the pdf creation process in the showcase thread about my 360° feedback/survey tool and so I went ahead and set my little pdf helper module to public.
      Description from PW Weekly:
       
      Modules Directory: https://modules.processwire.com/modules/rock-pdf/
      Download & Docs: https://github.com/BernhardBaumrock/RockPDF
       
      You can combine it easily with RockReplacer: 
      See also a little showcase of the RockPdf module in this thread:
       
×
×
  • Create New...