apeisa Posted December 30, 2014 Share Posted December 30, 2014 Interesting! Thanks for your patience. Can you post an issue to GitHub with that information? Link to comment Share on other sites More sharing options...
NorbertH Posted December 30, 2014 Share Posted December 30, 2014 I go and try to reproduce this on another server first , copying the full page right now good N8Edit:The Server i wanted to move this has moved itself to a new location so for the moment i am stuck till the admin has send me new accessdata. So i guess its best to whish a happy new Year and continue this discussion next year ;-) Link to comment Share on other sites More sharing options...
NorbertH Posted January 6, 2015 Share Posted January 6, 2015 Finally found time to do some more testing , and posted all results on Github. Basically it seems like the module created exessive memory usage but it seems really strange to me ... https://github.com/apeisa/UserGroups/issues/39 Link to comment Share on other sites More sharing options...
quickjeff Posted March 9, 2015 Share Posted March 9, 2015 Hi Guys, So I have this navigation setup for a site, it can be found here: https://processwire.com/talk/topic/5680-bootstrap-3-navigation-with-multiple-leveltier-fix/ However, I have also added this module to the site which works great: http://modules.processwire.com/modules/custom-page-roles/ Any ideas for displaying the navigation links based on the logged in users ability to see the page? Figured I would ask around before I dove right in. Here is the nav code: function renderChildrenOf($pa, $output = '', $level = 0) { $output = ''; $level++; foreach ($pa as $child) { $atoggle = ''; $class = ''; if ($child->numChildren && count($child->parents) == 1) { $class .= 'dropdown'; $atoggle .= ' class="dropdown-toggle" data-toggle="dropdown"'; } else if ($child->numChildren && count($child->parents) > 1) { $class .= 'dropdown-submenu'; $atoggle .= ' class="dropdown-toggle"'; } else if ($child->numChildren && $child->id != 1 ) { $class .= 'dropdown-menu'; } // Makes the current page and it's top level parent add an active class $class .= ($child === wire("page") || $child === wire("page")->rootParent) ? " active" : ''; $class = strlen($class) ? " class='" . trim($class) . "'" : ''; if ($child->numChildren && count($child->parents) == 1) { // Add Caret if have children $output .= "<li$class><a href='$child->url'$atoggle>$child->title <b class='caret'></b></a>"; } else if ($child->numChildren && count($child->parents) > 1) { $output .= "<li$class><a tabindex='-1' href='$child->url'$atoggle>$child->title</a>"; } else { $output .= "<li$class><a href='$child->url'$atoggle>$child->title</a>"; } // If this child is itself a parent and not the root page, then render it's children in their own menu too... if ($child->numChildren && $child->id != 1) { $output .= renderChildrenOf($child->children, $output, $level); } $output .= '</li>'; } $outerclass = ($level == 1) ? "nav navbar-nav" : 'dropdown-menu'; return "<ul class='$outerclass'>$output</ul>"; } // bundle up the first level pages and prepend the root home page $homepage = $pages->get(1); $pa = $homepage->children; //$pa = $pa->prepend($homepage); // Set the ball rolling... echo renderChildrenOf($pa); ?> Link to comment Share on other sites More sharing options...
Macrura Posted March 9, 2015 Share Posted March 9, 2015 I'm using sort of the same function, and although my setup is different (i have a custom menu generated from a branch on the tree) this might help, i use this right after the opening foreach: $menuVis = true; if($child->menu_roles->count()) { foreach($child->menu_roles as $cmr) { $menuVis = false; $cmrRole = wire('roles')->get("$cmr->name"); if (wire("user")->hasRole("$cmrRole") ) { $menuVis = true; break; } } } if($menuVis == false) continue; 2 Link to comment Share on other sites More sharing options...
quickjeff Posted March 9, 2015 Share Posted March 9, 2015 Hi Marcrura, You are also using the same module? Link to comment Share on other sites More sharing options...
Macrura Posted March 9, 2015 Share Posted March 9, 2015 @quickjeff, i'm not using that module, but the code i posted could probably be adjusted to work for it, because as i see in the module description Now when you edit a page using a template that has this field, you'll have checkboxes for roles that you can choose to define access from. so wouldn't you be able to use that snippet in some form to see if the menu item's page should be output? Link to comment Share on other sites More sharing options...
quickjeff Posted March 10, 2015 Share Posted March 10, 2015 Working like a charm! 1 Link to comment Share on other sites More sharing options...
Macrura Posted March 10, 2015 Share Posted March 10, 2015 hey quickjeff - maybe you could post your final code, to see how it was adjust for the use case? cheers! 3 Link to comment Share on other sites More sharing options...
quickjeff Posted March 11, 2015 Share Posted March 11, 2015 With the assistance of Macrura and another thread in this awesome community, I successfully have also been able to manipulate what menu items display in the navigation based on the users page role. Example is using bootstrap navigation. hey quickjeff - maybe you could post your final code, to see how it was adjust for the use case?cheers! Code below: <div id="navbar" class="navbar-collapse collapse"> <?php function renderChildrenOf($pa, $output = '', $level = 0) { $output = ''; $level++; foreach ($pa as $child) { $atoggle = ''; $class = ''; //Check if the user is allowed to view nav links $menuVis = true; if($child->page_roles) { foreach($child->page_roles as $cmr) { $menuVis = false; $cmrRole = wire('roles')->get("$cmr->name"); if (wire("user")->hasRole("$cmrRole") ) { $menuVis = true; break; } } } if($menuVis == false) continue; if ($child->numChildren && count($child->parents) == 1) { $class .= 'dropdown'; $atoggle .= ' class="dropdown-toggle" data-toggle="dropdown"'; } else if ($child->numChildren && count($child->parents) > 1) { $class .= 'dropdown-submenu'; $atoggle .= ' class="dropdown-toggle"'; } else if ($child->numChildren && $child->id != 1 ) { $class .= 'dropdown-menu'; } // Makes the current page and it's top level parent add an active class $class .= ($child === wire("page") || $child === wire("page")->rootParent) ? " active" : ''; $class = strlen($class) ? " class='" . trim($class) . "'" : ''; if ($child->numChildren && count($child->parents) == 1) { // Add Caret if have children $output .= "<li$class><a href='$child->url'$atoggle>$child->title <b class='caret'></b></a>"; } else if ($child->numChildren && count($child->parents) > 1) { $output .= "<li$class><a tabindex='-1' href='$child->url'$atoggle>$child->title</a>"; } else { $output .= "<li$class><a href='$child->url'$atoggle>$child->title</a>"; } // If this child is a parent and not the root page, then render it's children in menu if ($child->numChildren && $child->id != 1) { $output .= renderChildrenOf($child->children, $output, $level); } $output .= '</li>'; } $outerclass = ($level == 1) ? "nav navbar-nav" : 'dropdown-menu'; return "<ul class='$outerclass'>$output</ul>"; } // bundle up the first level pages and prepend the root home page $homepage = $pages->get(1); $pa = $homepage->children; $pa = $pa->prepend($homepage); echo renderChildrenOf($pa); ?> </div> Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now