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

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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By OLSA
      Hello for all,
      ConfigurationForm fieldtype module is one my experiment from 2016.
      Main target to build this module was to store multiple setup and configuration values in just 1 field and avoid to use 1 db table to store just single "number of items on page", or another db table to store "layout type" etc. Thanks to JSON formatted storage this module can help you to reduce number of PW native fields in project, save DB space, and reduce number of queries at front-end.
      Install and setup:
      Download (at the bottom ), unzip and install like any other PW module (site/modules/...). Create some filed using this type of field (ConfigurationForm Fieldtype) Go to field setup Input tab and drag some subfields to container area (demo). Set "Name" and other params for subfields Save and place field to templates ("Action tab") How to use it:
      In my case, I use it to store setup and configurations values, but also for contact details, small content blocks... (eg. "widgets").
      Basic usage example:
      ConfigForm fieldtype "setup" has subfields:
      "limit", type select, option values: 5, 10, 15, 20
      "sort", type select, option values: "-date", "date",  "-sort", "sort"
      // get page children (items) $limit = isset($page->setup->limit) ? $page->setup->limit : 10; $sort = isset($page->setup->sort) ? $page->setup->sort : '-sort'; $items = $page->children("limit=$limit, sort=$sort");  
      Screenshots:


       
      Notes:
      Provide option to search inside subfields Provide multilanguage inputs for text and textarea field types Provide option for different field layout per-template basis Do not place/use field type "Button" or "File input" because it won't works. Please read README file for more details and examples Module use JSON format to store values. Text and textarea field types are multilanguage compatible, but please note that main target for this module was to store setup values and small content blocks and save DB space. Search part inside JSON is still a relatively new in MySQL (>=5.77) and that's on you how and for what to use this module.
      Thanks:
      Initial point for this fieldtype was jQuery plugin FormBuiled and thanks to Kevin Chappel for this plugin.
      In field type "link" I use javascript part from @marcostoll module and thanks to him for that part.
      Download:
      FieldtypeConfigForm.zip
      Edit: 14. August 2018. please delete/uninstall previously downloaded zip
      Regards.
         
    • 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://gitlab.com/baumrock/RockPdf
       
      You can combine it easily with RockReplacer: 
      See also a little showcase of the RockPdf module in this thread:
       
    • By bernhard
      WHY?
      This module was built to fill the gap between simple $pages->find() operations and complex SQL queries.
      The problem with $pages->find() is that it loads all pages into memory and that can be a problem when querying multiple thousands of pages. Even $pages->findMany() loads all pages into memory and therefore is a lot slower than regular SQL.
      The problem with SQL on the other hand is, that the queries are quite complex to build. All fields are separate tables, some repeatable fields use multiple rows for their content that belong to only one single page, you always need to check for the page status (which is not necessary on regular find() operations and therefore nobody is used to that).
      In short: It is far too much work to efficiently and easily get an array of data based on PW pages and fields and I need that a lot for my RockGrid module to build all kinds of tabular data.

      Basic Usage

       
      Docs & Download
      https://modules.processwire.com/modules/rock-finder/
      https://gitlab.com/baumrock/RockFinder/tree/master
       
      Changelog
      180810, v1.0.5, basic support for options fields 180528, v1.0.4, add custom select statement option 180516, change sql query method, bump version to 1.0.0 180515, multilang bugfix 180513, beta release <180513, preview/discussion took place here: https://processwire.com/talk/topic/18983-rocksqlfinder-highly-efficient-and-flexible-sql-finder-module/
    • By Thomas Diroll
      Hi guys I'm relatively new to PW and just finished developing a page for a client. I was able to include all necessary functionality using the core fieldtypes but now I it seems that I need to extend them with a custom one. What I need is a simple button, that copies the absolute url (frontend not PW-backend) of the page which is currently edited to the clipboard. As this feature is only needed inside a specific template, I tend to use a custom fieldtype which provides this feature. I've been looking inside the core modules code (eg. FieldtypeCheckbox.module) but I don't really get the structure of it and how its rendered to the admin page. I also didn't find a lot of tutorials covering custom fieldtypes.
      Maybe some of you could give me some tips on how to write a basic custom fieldtype that renders a button which copies the value of
      page->httpUrl() to the clipboard using JS. Thanks!
    • By bernhard
      Some of you might have followed the development of this module here: https://processwire.com/talk/topic/15524-previewdiscussion-rockdatatables/ . It is the successor of "RockDataTables" and requires RockFinder to get the data for the grid easily and efficiently. It uses the open source part of agGrid for grid rendering.
       
      WHY?
      ProcessWire is awesome for creating all kinds of custom backend applications, but where it is not so awesome in my opinion is when it comes to listing this data. Of course we have the built in page lister and we have ListerPro, but none of that solutions is capable of properly displaying large amounts of data, for example lists of revenues, aggregations, quick and easy sorts by the user, instant filter and those kind of features. RockGrid to the rescue 😉 
       
      Features/Highlights:
      100k+ rows Instant (client side) filter, search, sort (different sort based on data type, eg "lower/greater than" for numbers, "contains" for strings) extendable via plugins (available plugins at the moment: fullscreen, csv export, reload, batch-processing of data, column sum/statistics, row selection) all the agGrid features (cell renderers, cell styling, pagination, column grouping etc) vanilla javascript, backend and frontend support (though not all plugins are working on the frontend yet and I don't plan to support it as long as I don't need it myself)  
      Limitations:
      While there is an option to retrieve data via AJAX the actual processing of the grid (displaying, filtering, sorting) is done on the client side, meaning that you can get into troubles when handling really large datasets of several thousands of rows. agGrid should be one of the most performant grid options in the world (see the official example page with a 100k row example) and does a lot to prevent problems (such as virtual row rendering), but you should always have this limitation in mind as this is a major difference to the available lister options that do not have this limitation.
      Currently it only supports AdminThemeUikit and I don't plan to support any other admin theme.
       
      Download: https://gitlab.com/baumrock/RockGrid
      Installation: https://gitlab.com/baumrock/RockGrid/wikis/Installation
      Quikckstart: https://gitlab.com/baumrock/RockGrid/wikis/quickstart
      Further instructions: https://gitlab.com/baumrock/RockGrid/wikis/quickstart#further-instructions
       
      Module status: alpha, License: MIT
      Note that every installation and uninstallation sends an anonymous google analytics event to my google analytics account. If you don't want that feel free to remove the appropriate lines of code before installation/uninstallation.
       
      Contribute:
      You can contribute to the development of this and other modules or just say thank you by
      testing, reporting issues and making PRs at gitlab liking this post buying me a drink: paypal.me/baumrock/5 liking my facebook page: facebook.com/baumrock hiring me for pw work: baumrock.com  
      Support: Please note that this module might not be as easy and plug&play as many other modules. It needs a good understanding of agGrid (and JavaScript in general) and it likely needs some looks into the code to get all the options. Please understand that I can not provide free support for every request here in the forum. I try to answer all questions that might also help others or that might improve the module but for individual requests I offer paid support for 60€ per hour.
       
      Changelog
      180730 support subdir installations 180711 bugfix (naming issue) 180630 alpha realease  
      Use Cases / Examples:
      Colored grid cells, Icons, Links etc. The Grid also has a "batcher" feature built in that helps communicating with the server via AJAX and managing resource intensive tasks in batches:

      Filters, PW panel links and instant reload on panel close:

      You can combine the grid with a chart library like I did with the (outdated) RockDataTables module: