kongondo

Menu Builder

Recommended Posts

44 minutes ago, Jozsef said:

data protected => array ()

Hmm. This says your menu is empty.

What about this one on line # 105?

// on line #105
d($rawMenuItems,'raw menu items');

 

Share this post


Link to post
Share on other sites

That has no output at all. I'm very curious what is that, I must overlook something.

Screen Shot 2018-11-19 at 23.18.40.png

Screen Shot 2018-11-19 at 23.18.23.png

Share this post


Link to post
Share on other sites
35 minutes ago, Jozsef said:

That has no output at all.

No output meaning nothing appears on screen or no output meaning Tracy says the array is empty? If the former, it means the condition on line #96 is met, meaning the menu is cached (Menu Builder cache). Did you cache the menu? Even in that case, a menu should be built from cache (unless it got deleted by mistake?). Try this on line #100 please:

d($menu, 'Cached menu');

Does it return anything?

Edited by kongondo

Share this post


Link to post
Share on other sites

That also returns nothing. That is, no output appears on screen from Tracy.

Share this post


Link to post
Share on other sites

That's strange. I'm not sure where the items are getting lost. Btw, my Tracy calls should have been bd() rather than d(). Please try bd() in the previous two as well as this on line 86:

bd($menuItems);

With the bd calls, have a look in the Tracy bar.

Is the site online? If I could get a temporary access, I could have a quick look.

Share this post


Link to post
Share on other sites

It's not live, unfortunately. If I do a

print_r($menuItems)

in line 86, the output is ' main_menu' instead of an array. Interestingly, there's a space before the name of the menu, I'm not sure if it's important.
I'll try to upload it to the server later today.
 

Share this post


Link to post
Share on other sites
22 minutes ago, Jozsef said:

there's a space before the name of the menu,

That's it! If you are logged in as superuser MB should have thrown an error. If not logged in or for non superusers, it will fail silently. Are you logged in as superuser? Try remove the space after that and see if it works.

Edited by kongondo

Share this post


Link to post
Share on other sites

But that's the thing, there's no space in the menu name anywhere so I don't know where it came from.
I sent you a PM with login details.

Share this post


Link to post
Share on other sites

Solved:
It turned out I had no template file for any of the pages in the menu and the module checks if pages are viewable.
Since non of the pages were viewable, menuItems returned an empty array.
Thanks @kongondo for the help and pointing me to the right direction. All is well now.

Share this post


Link to post
Share on other sites

I can't see an option to apply classes on the link itself, on the <a> tag. When using Bootstrap, links must have the nav-link class.
Did I miss something? What workaround can I use without messing with the module code?
The module is working great, this is really the only thing I missed.

Share this post


Link to post
Share on other sites
2 hours ago, Jozsef said:

I can't see an option to apply classes on the link itself, on the <a> tag.

It is not possible.

2 hours ago, Jozsef said:

When using Bootstrap, links must have the nav-link class.
Did I miss something? What workaround can I use without messing with the module code?

For such custom requirements, we suggest use of the method getMenuItems(). It gives you total freedom. Have a read here and see these examples. You'll need to do a bit of custom work. Shout if you need help.

Edited by kongondo
  • Like 2

Share this post


Link to post
Share on other sites

HI guys,

I'm using twig for my frontend and I'm trying to pass $options to the menu for rendering.

For some reason I can't achieve what I want, as I seem unable to pass associative arrays to the render() call in twig. I'm using markupMenuBuilder to render the menu.

I generate it as follows:   

   $menuBuilder = $modules->get('MarkupMenuBuilder');
   $options = array(
    'has_children_class' => 'has_children',
    'current_class' => 'active',
    'menu_css_id' => 'main',
    'menu_css_class' => 'nav',
);

$view->set('options', $options);
$view->set('menuBuilder', $menuBuilder);

to make menuBuilder accept the options I would have to pass them to the render function in php like this:

   echo $menu->render('sidenav', $options)

 

I can't get this to work in twig since I don't get how to pass the options to the render function when using twig. Can anyone point me in the right direction plz?

 

Best whishes deM

Share this post


Link to post
Share on other sites

This sounds like a Twig issue. I've never used Twig so can't help, unfortunately.

Share this post


Link to post
Share on other sites

I guess you should set the rendered html to a twig variable in the php file.

Share this post


Link to post
Share on other sites

 @kongondo First. Thank you for this great module!

I'm writing this in the hope it can help someone.

I'm using the latest PW version. Using the module I received this error when switching to a different language from the default one.

No menu items found!

To solve the issue I went in the admin and find the Menu Builder page (under Admin>Setup)

image.png.2dbdf67448bc5d0cf75946bf3a9ca40a.png

then I edited both the "Menu Builder" page and "mainmenu" page (this a menu that I built in Menu Builder)  and set the other language to active.

image.thumb.png.5d2f99593695b7658becce45c493e988.png

It seems the module doesn't set as active new pages in languages different from default.

My PW installation by default set it to false. 

Hope this helps. Ciao

  • Like 2

Share this post


Link to post
Share on other sites
54 minutes ago, manlio said:

It seems the module doesn't set as active new pages in languages different from default.

That's correct. Full multi-lingual support has been on my todo list for a long time. Hopefully I'll get some time soon to look into it.

56 minutes ago, manlio said:

I'm writing this in the hope it can help someone.

Thanks for sharing your workaround with others.

  • Like 1

Share this post


Link to post
Share on other sites

I have just installed the MenuBuilder and wanted to rebuild a menu as in the standard UIKIT design of PW.

How can I get it that the submenus are in a DIV?

Can I install it somewhere in the options or in a template?

Because by default it is UL => LI => UL => LI
AT UIKIT IT IS YES BUT UL => LI => DIV => UL => LI

Thank you for your help!

Share this post


Link to post
Share on other sites
11 hours ago, csaeum said:

How can I get it that the submenus are in a DIV?

Have a look these examples:

you will need to use getMenuItems() method.

Share this post


Link to post
Share on other sites

Hello!

I like to use the menu builder module. I like the freedom for the website administrator to add and remove easily pages. But if I use the menubuilder with more than one menus on a page i got an error with the language code. It is a multilanguage website.

Does anyone have experience with such an error?

Thanks for your help!

Best greetings

Gerald @mate-themes

Share this post


Link to post
Share on other sites

@MateThemes

Could you please share your code and the error you are getting? 

Also, make sure that you are not passing a menu name or title as the first argument of the render method. In ML setup it should be id, an array of menu items or page object. 

  • Like 1

Share this post


Link to post
Share on other sites

Hello everyone!!!

Maybe I am missing something. First I need to say the module works now fine, but as i said, i am missing something. I have following html markup:

<div class="uk-navbar-center uk-visible@m">
  <!-- Main Menu -->
  <ul class='uk-navbar-nav'>
    <li class="uk-active"><a href="/">Home</a></li>
    <li><a href="/der-schiort/">Schiort</a></li>
    <li><a href="#">Test</a>
      <div class='uk-navbar-dropdown'>
        <ul class='uk-nav uk-navbar-dropdown-nav'>
          <li><a href="/impressum/">Impressum</a></li>
          <li><a href="/datenschutz/">Datenschutz</a></li>
        </ul>
    </li>
  </ul>
</div>

And following Menubuilder Code for the Menu:

<?php
/**
* Builds a nested list (menu items) of a single menu.
* 
* A recursive function to display nested list of menu items.
*
* @access private
* @param Int $parent ID of menu item.
* @param Array $menu Object of menu items to display.
* @param Int $first Helper variable to designate first menu item.
* @return string $out.
*
*/
function buildMenuFromObject($parent = 0, $menu, $first = 0) {
  if(!is_object($menu)) return;
  $out = '';
  $has_child = false;
  foreach ($menu as $m) {
    $newtab = $m->newtab ? " target='_blank'" : '';            
    // if this menu item is a parent; create the sub-items/child-menu-items
    if ($m->parentID == $parent) {// if this menu item is a parent; create the inner-items/child-menu-items
        // if this is the first child
        if ($has_child === false) {                    
            $has_child = true;// This is a parent                        
            if ($first == 0){                            
              $out .= "<ul class='uk-navbar-nav'>\n";                            
              $first = 1;
            }                        
            else $out .= "\n<div class='uk-navbar-dropdown'>\n<ul class='uk-nav uk-navbar-dropdown-nav'>\n";
        }
        $class = $m->isCurrent ? ' class="uk-active"' : '';
        // a menu item
        $out .= '<li' . $class . '><a href="' . $m->url . '"' . $newtab . '>' . $m->title;                    
        // if menu item has children
        if ($m->isParent) {
          $out .= '</a>';
        }
        
        else $out .= '</a>';         
        // call function again to generate nested list for sub-menu items belonging to this menu item. 
        $out .= buildMenuFromObject($m->id, $menu, $first);
        $out .= "</li>\n";
    }// end if parent
  
  }// end foreach
  if ($has_child === true) $out .= "</ul>\n";
  return $out;
}
##################################
/* grab menu items using MarkupMenuBuilder */
$mb = $modules->get('MarkupMenuBuilder');// get Menu Builder
/* get menu the menu we want (i.e. a menu created and published using ProcessMenuBuilder) */
// we can pass the menu's Page, page ID, title, name or its menu items string to getMenuItems()
#$menu = $pages->get(1299);// pass a Page
$menu = 1041;// pass an ID
#$menu = 'main';// pass a name
// passing an array
#$jsonStr = $pages->get(1299)->menu_items;
#$arrayFromJSON = json_decode($jsonStr, true);
#$menu = $arrayFromJSON;// pass an array
#$menu = 'Main';// pass a title
/* only these 3 options apply to getMenuItems() */
$options = array('default_title'=> 1, 'default_class'=> 'cool_menu_class', 'current_class_level' => 4);
/* grab menu items as a WireArray with Menu objects */
$menuItems = $mb->getMenuItems($menu, 2, $options);// called with options and 2nd argument = 2 {return Menu (WireArray object)}
#$menuItems = $mb->getMenuItems($menu);// if calling without without options; 2nd argument defaults to 2
?>
<?php
  // build menu from array (example 1b only)
  echo buildMenuFromObject(0, $menuItems);
?>

How can I close the <div class="uk-navbar-dropdown">? Everything I've tried seems not to work!

Thank you very much for your help!!!

Edited by MateThemes

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 Sebi
      I've created a small module which lets you define a timestamp after which a page should be accessible. In addition you can define a timestamp when the release should end and the page should not be accessable any more.
      Github: https://github.com/Sebiworld/PageAccessReleasetime
      Usage
      PageAccessReleasetime can be installed like every other module in ProcessWire. Check the following guide for detailed information: How-To Install or Uninstall Modules
      After that, you will find checkboxes for activating the releasetime-fields at the settings-tab of each page. You don't need to add the fields to your templates manually.
      Check e.g. the checkbox "Activate Releasetime from?" and fill in a date in the future. The page will not be accessable for your users until the given date is reached.
      If you have $config->pagefileSecure = true, the module will protect files of unreleased pages as well.
      How it works
      This module hooks into Page::viewable to prevent users to access unreleased pages:
      public function hookPageViewable($event) { $page = $event->object; $viewable = $event->return; if($viewable){ // If the page would be viewable, additionally check Releasetime and User-Permission $viewable = $this->canUserSee($page); } $event->return = $viewable; } To prevent access to the files of unreleased pages, we hook into Page::isPublic and ProcessPageView::sendFile.
      public function hookPageIsPublic($e) { $page = $e->object; if($e->return && $this->isReleaseTimeSet($page)) { $e->return = false; } } The site/assets/files/ directory of pages, which isPublic() returns false, will get a '-' as prefix. This indicates ProcessWire (with activated $config->pagefileSecure) to check the file's permissions via PHP before delivering it to the client.
      The check wether a not-public file should be accessable happens in ProcessPageView::sendFile. We throw an 404 Exception if the current user must not see the file.
      public function hookProcessPageViewSendFile($e) { $page = $e->arguments[0]; if(!$this->canUserSee($page)) { throw new Wire404Exception('File not found'); } } Additionally we hook into ProcessPageEdit::buildForm to add the PageAccessReleasetime fields to each page and move them to the settings tab.
      Limitations
      In the current version, releasetime-protected pages will appear in wire('pages')->find() queries. If you want to display a list of pages, where pages could be releasetime-protected, you should double-check with $page->viewable() wether the page can be accessed. $page->viewable() returns false, if the page is not released yet.
      If you have an idea how unreleased pages can be filtered out of ProcessWire selector queries, feel free to write an issue, comment or make a pull request!
    • By David Karich
      Thanks to the great Pro module "RepeaterMatrix" I have the possibility to create complex repeater items. With it I have created a quite powerful page builder. Many different content modules, with many more possible design options. The RepeaterMatrix module supports the cloning of items, but only within the same page. Now I often have the case that very design-intensive pages and items are created. If you want to use this module on a different page (e.g. in the same design), you have to rebuild each item manually every time.
      With this proof of concept I have created a module which adds the feature to copy a repeater item to the clipboard so that you can paste this item to another page with the same repeater field. The module has been developed very rudimentarily so far. It is currently not possible to copy nested items. There is also no check of Min/Max. You can also only copy items that have the same field on different pages. And surely you can solve all this more elegantly with AJAX. But personally I lack the deeper understanding of the repeaters. Also missing on the Javascript side are event triggers for the repeaters, which would make it easier. Like e.g. RepeaterItemInitReady or similar.
      it would be great if @ryan would implement this functionality in the core of RepeaterMatrix. I think he has better ways to implement this. Or what do you think, Ryan?
      Everybody is welcome to work on this module and improve it, if it should not be integrated into the matrix core. Therefore I put it for testing and as download on GitHub: https://github.com/FlipZoomMedia/InputfieldRepeaterMatrixDublicate
      You can best see the functionality in the screencast: 
       
    • By anderson
      Hi,
      Please take a look at this:
      https://templatemag.com/demo/Good/
      The upper nav bar, including dropdowns like "pages" and "portfolios", what do you call this whole thing? At first I guess it's called "dropdown nav bar", but seems not.
      AND of course, what's the simplest way/module to achieve this in PW?
      Thanks in advance.
    • By Sebi2020
      Hey, I'm new and I created a simple module for tagging pages because I didn't found a module for it (sadly this is not a core feature). This module is licensed under the GPL3 and cames with absolutly no warranty at all. You should test the module before using it in production environments. Currently it's an alpha release. if you like the module or have ideas for improvements feel free to post a comment. Currently this fieldtype is only compatible with the Inputfield I've created to because I haven't found  an Inputfield yet, that returns arrays from a single html input.
      Greetings Sebi2020
      FieldtypeTags.zip.asc
      InputfieldTagify.zip
      InputfieldTagify.zip.asc
      FieldtypeTags.zip
    • By psy
      Background
      I'm creating a module to integrate https://pushalert.co/ into ProcessWire. You actually don't even need a module. You could just use the "Other Websites" javascript provided by PushAlert for basic functionality, ie send a broadcast notification to all subscribers. This is essentially what all the other integrations, including WordPress, do. The WP integration installs a widget with a form enabling the admin to enter details such as title, message, etc from a blog post. It does not:
      collect any statistics within the CMS about the notification enable audience fine tuning to eg a particular subscriber or subscriber segment within WP. The admin needs to use the PA dashboard for that functionality PushAlert has a javascript and REST API. It's intended that this module will use both. https://pushalert.co/documentation 
      What my module does so far:
      associate a subscription with a user. FE user clicks a button on the website front end to subscribe and/or agrees to the browser popup to accept notifications from this site send broadcast push alerts from a page within admin It doesn't have a 'widget' but easy enough to create a fieldsetpage with the relevant fields and add that fs page to any appropriate templates, then with a hook, send the notification. Need to be careful that once published/sent, the notification is not automatically re-sent on subsequent page edits.
      Looking for help/collaboration on how best:
      to send a notification, eg from a blog post, then track the statistics. Dilemma is that the push notification must come from the admin page. Responses go to the sending page which, as it's an admin page, is restricted and will not accept the https response. This is where the other CMS integrations stop. The only json response from PushAlert is the status, eg 'success', and the notification id. There is no opportunity at this point to capture the sending page id. handle, 'once sent on page publish', do not automatically resend on future page edits Am thinking along the lines that FS Page will have a @kongondo runtime markup field https://modules.processwire.com/modules/fieldtype-runtime-markup/ to pull the stats from PushAlert. Every time an admin visits the page, the stats will update.
      Once an admin checks the 'Send notification on page publish' checkbox, a hook creates new front end page that records the 'sender page', sends the notification request to PA, which then uses that newly created frontend page, as the response endpoint. Another rook re-associates the front end page with the admin page (eg blog post), to update the stats.
      Potential use cases:
      Notify individual and/or users with a particular role of an event, eg "New work opportunity" for job seekers; new blog post published; entries now open, etc...
      Looking for help/ideas/collaboration on this module. Please let me know if you're interested and as I do, believe this would be a great addition to ProcessWire