kongondo

Menu Builder

Recommended Posts

Menu Builder
 

As of 29 December 2017 ProcessWire versions earlier than 3.x are not supported

Modules Directory
Project Page
Read Me (How to install, use, etc..)

For highly customisable menus, please see this post.

If you want a navigation that mirrors your ProcessWire page tree, the system allows you to easily create recursive menus using either vanilla PHP or Soma's great MarkupSimpleNavigation. In some cases, however, you may wish to create menus that:
1. Do not mirror you site's page tree (hirarchies and ancestry); and
2. You can add custom links (external to your site) to.


That is primarily where Menu Builder comes in. It is also helpful if you:
3. Prefer creating menus via drag and drop
4. Have a need for menus (or other listings) that will be changing regularly or that you want to allow your admin users to edit.


The issue of custom menus is not new here in the forums. The difference is that this module allows you to easily create such menus via drag and drop in the Admin. Actually, you can even use it to just create some list if you wanted to. In the backend, the module uses the jQueryUI plugin nestedSortable by Manuele J Sarfatti for the drag and drop and is inspired in part by the WP Custom Menu feature.
 
Please read the Read Me completely before using this module. 

For Complex or highly-customised menus, it is recommended to use the getMenuItems() method as detailed in this post.
 
Features

  • Ability to create menus that do not mirror your ProcessWire Page Tree hierarchy/structure
  • Menus can contain both ProcessWire pages and custom links
  • Create menu hierarchies and nesting via drag and drop
  • Easily add CSS IDs and Classes to each menu item on creating the menu items (both custom and from ProcessWire pages) or post creation.
  • Optionally set custom links to open in a new tab
  • Change menu item titles built from ProcessWire pages (without affecting the original page). E.g. if you have a page titled 'About Us' but you want the menu item title to be 'About'
  • Readily view the structure and settings for each menu item
  • Menus stored as pages (note: just the menu, not the items!)
  • Menu items stored as JSON in a field in the menu pages (empty values not stored)
  • Add menu items from ProcessWire pages using page fields (option to choose between PageAutocomplete and AsmSelect [default]) or a Selector (e.g. template=basic-page, limit=20, sort=title).
  • For page fields, you can specify a selector to return only those specified pages for selection in the page field (i.e. asm and autocomplete)
  • For superusers, optionally allow markup in your menu titles, e.g. <span>About</span>
  • Menu settings for nestedSortable - e.g. maxLevels (limit nesting levels)
  • Advanced features (e.g. add pages via selector, menu settings) currently permissible to superadmins only (may change to be permission-based)
  • Delete single or all menu items without deleting the menu itself
  • Lock down menus for editing
  • Highly configurable MarkupMenuBuilder - e.g. can pass menu id, title, name or array to render(); Passing an array means you can conditionally manipulate it before rendering, e.g. make certain menu branches visible only to certain users [the code is up to you!] 
  • Optionally grab menu items only (as a Menu object WireArray or a normal array) and use your own code to create custom highly complex menus to meet any need.
  • More...

In the backend, ProcessMenuBuilder does the menu creation. For the frontend, menus are displayed using MarkupMenuBuilder.

Credits

In this module's infancy (way back!), I wanted to know more about ProcessWire modules as well as improve my PHP skills. As they say, what better way to learn than to actually create something? So, I developed this module (instead of writing PW tutorials as promised, tsk, tsk, naughty, naughty!) in my own summer of code :). Props to Wanze, Soma, Pete, Antti and Ryan whose modules I studied (read copied ;)) to help in my module development and to Teppo for his wonderful write-up on the "Anatomy of fields in ProcessWire" that vastly improved my knowledge and understanding of how PW works. Diogo and marcus for idea about using pages (rather than a custom db table), onjegolders for his helpful UI comments, Martijn Geerts, OrganizedFellow, dazzyweb and Mike Anthony for 'pushing me' to complete this module and netcarver for help with the code.
 
Screens
mb-0.0.2-001.pngmb-0.0.2-002.pngmb-0.0.2-003.pngmb-0.0.2-004.pngmb-0.0.2-005.pngmb-0.0.2-006.pngmb-0.0.2-007.pngmb-0.0.2-008.pngmb-0.0.2-009.pngmb-0.0.2-010.png

Edited by kongondo
ProcessWire 3.x support only
  • Like 34

Share this post


Link to post
Share on other sites

I love it.

I said before: "I like it that way, PLEASE stay talkin' on the forums"

Now I think, stay away from the forums and go code for us :)

  • Like 2

Share this post


Link to post
Share on other sites

Very impressive Kongondo, looks great.

If there were a way of combining the two steps into one (adding new items & arranging items) I think it would be a better experience for the user. 

1) Add a new item

2) Choose from a dropdown whether it's a native page or external

3) Add item and item details.

I can understand that with required fields it may be harder to achieve all of this from within the item boxes.

The other slight improvement would be if the page tree remains open when an item has been clicked?

But it already looks like a great addition to PW :)

PS Love the music!

  • Like 1

Share this post


Link to post
Share on other sites

Thanks all!

@onjegolders,

Good ideas, thanks for the suggestions, I'll look into them. 

music = Fourplay  - "Pineapple Getaway"

  • Like 1

Share this post


Link to post
Share on other sites

Awesome work Kongondo! Very impressive seeing it in action from your video too. 

Regarding the help-please section and security: is the Process tool intended primarily for superuser/developer use, or something that would be available to non-superusers? If exclusive to superusers (as many admin/developer helper tools can be), security becomes a much simpler task because we already assume they have access to do whatever they want. If not exclusive to superusers, then there's more to consider. With regards to SQL queries, it looks like you are doing a good job of sanitizing everything that gets bundled into a query. But for any string values, you might also want to run them through $str=$db->escape_string($str); just to complete it with the DB driver's own sanitization method. It's probably not technically necessary in any of the instances I saw, but it's just a good practice either way. Of course, you can also use numbered parameters in mysqli to avoid that issue, but I don't care for mysqli's implementation of this and generally don't use it (on the other hand, PDO's named parameters are great). 

  • Like 1

Share this post


Link to post
Share on other sites

@kongondo - do you think it would be ok to use this on a production site? I have to make a custom menu for a new site, and before i go and do it with pages, i wanted to maybe consider using this..

Share this post


Link to post
Share on other sites

Hi Macrura,

Sorry not to have picked this up sooner. I wouldn't use this on a live site just yet, mainly because the user has no way (yet) to delete individual menu items via the GUI. Unfortunately, I don't see myself having time to continue working on this until the end of the year most likely. Please feel free to explore a workaround or adapt it to your needs though, if you wish. Thanks. 

Cheers,

/k

Share this post


Link to post
Share on other sites

@Ryan,

Thanks for your comments. The original plan was to let non-superusers with the right permissions also use the module. This would enable them to build their own navigation systems easily, a la WP. However, besides security, that could lead to other issues such as wanton addition of menu items! I haven't made a final decision yet. We'll see.

  • Like 1

Share this post


Link to post
Share on other sites

@kongondo thank you - i did just go ahead and use my normal way of managing menus which is by setting up a menu page tree and then coding the output manually;

Welcome Back!

  • Like 1

Share this post


Link to post
Share on other sites

Yeah, incidentally I mentioned this elsewhere today. I got stuck on some recursive function :-). It's not high on my priority list atm but will have a rethink at some point...

  • Like 1

Share this post


Link to post
Share on other sites

No, sorry...I haven't. I didn't really think there would be interest....Hmm...I'll make a decision this week. If I take it up again I would have to change a few things now that I am a little bit wiser...We'll see.

Share this post


Link to post
Share on other sites

I, for one, would love a solid module that handles menu management. I have a large site coming up in a month or so that would require it. Automatic menu generation doesn't sit so well for me - so this is a must have. If you decide to not do it, then I'm sure I can make use of a page structure under admin to mimic the functionality... But, I think a dedicated module is better - especially for the client, who needs to be able to modify certain menus as and when needed.

  • Like 1

Share this post


Link to post
Share on other sites

OK, we are on. I have resumed work on this and taken a newish approach. Hope to post something by end of play tomorrow...

  • Like 5

Share this post


Link to post
Share on other sites

Update: Menu Builder Version 0.0.2 is now available.
 
I'll update the original post later + post a new video.
 
Main Changes:

  • Beta status
  • Menus stored as pages (note: just the menu, not the items!)
  • Menu items stored as JSON in a field in the menu pages (empty values not stored)
  • Add menu items from ProcessWire pages using page fields (option to choose between PageAutocomplete and AsmSelect [default]) or a Selector (e.g. template=basic-page, limit-20).
  • For page fields, you can specify a selector to return only those specified pages for selection in the page field (i.e. asm and autocomplete)
  • For page fields, now you can also add css classes and IDs as you add the items
  • Menu settings for nestedSortable - e.g. maxLevels (limit nesting levels)
  • Advanced features (e.g. add pages via selector, menu settings) currently permissible to superadmins only (may change to be permission-based)
  • Delete single or all menu items without deleting the menu itself
  • Lock down menus for editing
  • Highly configurable MarkupMenuBuilder - e.g. can pass menu id, title, name or array to render(); Passing an array means you can conditionally manipulate it before rendering, e.g. make certain menu branches visible only to certain users [untested and the code is up to you!] 
  • More...

Note:

  • Some nestedSortable features not yet implemented/working (some are not really necessary actually).
  • The module creates 3 fields (menu_items, menu_pages, menu_settings) and 1 template (menus). 
  • Menu pages are stored as children under the modules parent page (admin/setup/menu-builder/) - so not accessible in the frontend

Issues:
Drag and drop (ordering menu items) is some times finicky...something in the js I think or just my mouse.
 

Edited by kongondo
  • Like 12

Share this post


Link to post
Share on other sites

I haven't tested yet, but it looks very impressive - awesome job!

  • Like 1

Share this post


Link to post
Share on other sites

I just tested it and it's very nice.

I want to put a class on the menu submenu so on nested unordered list. Is there an option for this?

For example <ul class="submenu">

  • Like 2

Share this post


Link to post
Share on other sites
This is just what I needed - works brilliantly, and is easy to use. I do have a few suggestions, though:

  1. It would be nice to have compatibility for the <nav> tag - I use them in my menus instead of unordered lists.
  2. Also, I should be able to add a class and/or an ID to each menu.
  3. Lastly, it would be great if I could add a class to sub-menu <ul> as well as any menu-item <li>
Otherwise, this is fantastic - thank you :-)

Edit: Dazzyweb beat me to it! 

Share this post


Link to post
Share on other sites

@Mike Anthony Regarding suggestion 2: I think you could add a different class and/or ID to each menu by creating another differently named options array and give a different name for menu_css_id and menu_css_class then use these options in your other menu.

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 blad
      Hi guys!
      I just uploaded a module to explore files based on elFinder. By default it will show the "Files" folder.
      Screenshots:

      Video:
       
      To do:
       More options To fix:
       The function of rotating or scaling an image fails  Image editors Github:
      https://github.com/LuisSantiago/ProcessElFinder/
      I hope you like it.
    • By BitPoet
      I'm really in love with FormBuilder, but the one thing missing to match all my end users' expectations were repeatable field groups. Think repeaters, in ProcessWire terms. Our primary application of PW is our corporate intranet, so "lines" of fields are quite common in the forms I build. We have all kinds of request forms where the information for a varying number of colleagues needs to be entered (from meal order to flight booking request) and where it is simply impractical to send a form for each, and I don't want to clutter my forms with multiple instances of fields that may only get used ten percent of the time.
      That's why I started to build FormBuilderMultiplier (link to GitHub).
      What it does:
      Adds an option to make a regular Fieldgroup repeatable Lets you limit the number of instances of a Fieldgroup on the form Adds an "Add row" button the form that adds another instance of the Fieldgroup's fields Adds a counter suffix at the end of every affected field's label Stores the entered values just like regular fields Makes the entered values available in preview and email notifications Supports most text based fields, textareas and selects (really, I haven't had enough time to test all the available choices yet) What it doesn't do (yet):
      Support saving to ProcessWire pages (i.e. real Repeaters) I haven't tested all the validation stuff, Date/Time inputs etc. yet, but since I'm utterly swamped with other stuff at work, I didn't want to wait until I have it polished. Any feedback is welcome. There might also be some issues with different output frameworks that I haven't encountered yet. The forms I work with mostly use UIKit.
      Status:
      Still alpha, so test well before using it in the field.
      Known issues:
      When rows are added, the form's iframe needs to be resized, which isn't completely clean yet.
      How it works:
      The Fieldgroup settings are added through regular hooks, as is the logic that adds the necessary field copies for processing the form and displaying previews.
      "Multiplied" field instances are suffixed with _NUM, where NUM is an incremental integer starting from 1. So if you have add two fields named "surname" and "givenname" to a fieldgroup and check the "multiply" checkbox, the form will initially have "surname_1" and "givenname_1" field (I'm still considering changing that to make the risk to shoot oneself into the foot by having a regular "surname_1" field somewhere else in the form less likely).
      When a "row" is added, the first row is cloned through JS and the counter in the fields' IDs, names and "for" attributes as well as the counter in the label are incremented before appending the copies to the Fieldset container in the form.
      To keep backend and frontend in sync, a hidden field named [name of the fieldset]__multiplier_rows is added to the form. Both the backend and the frontend script use this to store and retrieve the number of "rows".
      ToDo:
      Naturally, add the option to store the data in real repeaters when saving to pages. Do a lot of testing (and likely fixing). Make a few things (like the "Add row" button label etc.) configurable in field(set) context. Add a smooth API to retrieve the multiplied values as WireArrays. The mandatory moving screenshot:

    • By MoritzLost
      Hello there,
      I'm working on a tiny textformatter module that searches the text for titles of other pages on your site and creates hyperlinks to them. I'm not sure if something like this exists already, but I haven't found anything in the module directory, so I wrote my own solution 🙂
      It's not properly tested yet and is still missing some functionality I would like to implement, so at the moment it should be considered in BETA. Features include limiting the pages that will get searched by template, and adding a custom CSS class to the generated hyperlinks. As I'm writing this I noticed that it will probably include unpublished and hidden pages at the moment, so yeah ... it's still in development alright 😅
      You can download the module from Github:
      https://github.com/MoritzLost/TextformatterPageTitleLinks
      There's some more information in the readme as well.
      Anyway, let me know what you think! I'm happy about any feedback, possible improvements or ideas on how to improve the module. Cheers.
    • By adrian
      This module provides a way to rapidly generate Page fields and the required templates and pages for use as a drop down select (or any other Page field type).
      This module will let you create a full page field setup in literally a few seconds 
      To use, run Page Field Select Creator from the Setup Menu
      Enter a Field Title, eg: Room Types Select Options - These will become the child pages that will populate the page field select options. There are two different options.
       
      Option 1. TITLE FIELD ONLY - enter one option per line, eg:
       
      Single
      Double
      Suite
       
       
      Option 2. MULTIPLE FIELDS - the first line is used for the field names and the first field must be 'Title'. Subsequent lines are the values for the fields, eg:
       
      Title, Number of Beds, Number of People, Kitchen Facilities
      Single, 1, 1, Fridge Only
      Double, 2, 2, Fridge Only
      Suite, 3, 6, Full Kitchen
        Choose the parent where the page tree of options will be created, eg a hidden "Options" parent page Select a "Deference in API as" option depending on your needs Choose the input field type Check whether "Allow new pages to be created from field?" should be enabled. As an example, if you entered "Room Types" as the field title, you would end up with all of the following automatically created:
      a fully configured page field called: room_types MULTIPLE FIELDS OPTION - 3 additional fields - number_of_beds, number_of_people, kitchen a parent template called: room_types a child template called: room_types_items (with either just a title field, or with the 3 additional fields as well) a parent page called: Room Types a series of child pages named and titled based on the per line entries in the Select Options textarea The templates are configured such that the "room_types_items" child template can only have the main "room_types" template as a parent, and vice versa.

      Then all you have to do is add the newly created page field to any template you want and you're ready to go!
       
      You can grab it from:
       
      Modules directory: http://modules.processwire.com/modules/process-page-field-select-creator/
      Github: https://github.com/adrianbj/ProcessPageFieldSelectCreator
       

    • 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://github.com/BernhardBaumrock/RockFinder
       
      Changelog
      180817, v1.0.6, support for joining multiple finders 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/