Typo3 Neos: show different Menu items to loggedin users of different access levels - typo3-flow

I have created menus in Neos backend. Each menu node corresponds to a plugin of a controlleraction.
These controller actions are defined in policy.yaml as resources with their flow access policy roles.
The template for menu is defined in root.ts2 which i took a copy from Typo3.NeosDemoTypo3Org package.
mainMenu part of root.ts2 is
mainMenu = Menu {
entryLevel = 1
templatePath = 'resource://ABC.Demo/Private/Templates/TypoScriptObjects/MainMenu.html'
maximumLevels = 3
site = ${site}
}
MainMenu.html is:
<div class="collapse navbar-collapse navbar-main-collapse">
<ul class="nav nav-pills nav-justified">
<f:for each="{items}" as="item" iteration="menuItemIterator">
<f:then>
<li class="active">
<neos:link.node node="{item.node}">{item.label}</neos:link.node>
</li>
</f:then>
<f:else>
<li>
<neos:link.node node="{item.node}">{item.label}</neos:link.node>
</li>
</f:else>
</f:if>
</f:for>
</ul>
</div>
If I use {parts.mainMenu -> f:format.raw()} in Default.html, it prints all the menu items defined at root of Neos site.
How can i show only those menu items in main menu of webpage for which the user has access to the corresponding resource defined in policy.yaml.
Can anybody give an idea, the way to achieve it.

You should set the access protection on the page node. Currently there no interface for this yet, but you can define access roles for the nodes in the database. See table:
typo3_typo3cr_domain_model_nodedata field accessroles.
It should be a serialized array of role names.
This will then correctly reflect in the menu. And don't forget to set the TYPO3.Neos:Editor role as well otherwise editors won't be able to modify those pages.
It would be quite complicated to fetch the plugins from each page and do access checks against them but that could of course be another option. I cannot directly give you any hints for that thou, because the node type would be different for each page, depending on the plugin.

Related

asp net core activate a controller and action with href? [duplicate]

I'm currently trying to make a website in ASP.NET Core MVC. In my layout page, I'm making a navigation bar to access all of the actions that can be reached through my controllers. I am however unable to create useful links.
<ul>
<li>Home</li>
<li>Index</li>
</ul>
My problem with this is that I still need the controller before the links and if I put the controller in front of the action like this
<ul>
<li>Home</li>
<li>What We've Done</li>
</ul>
When I click on one link and then the other, the link will end up being "myurl/home/home/page".
How can I create the link to only link to the exact page I want to?
You should use the anchor tag helper to build the markup for the link
<a asp-action="index" asp-controller="home">Home</a>
This will generate the correct relative path to the index action as the href property value of the anchor tag.

Sub menu with MvcSiteMapProvider

Currently i'm using the MvcSiteMapProvider to provide my sitemap. I'm now converting my menu to use the same XML. I have created a MyMenu.cshtml with the following code
#model MvcSiteMapProvider.Web.Html.Models.MenuHelperModel
#using MvcSiteMapProvider.Web.Html.Models
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
#foreach (var node in Model.Nodes) {
<li>#Html.DisplayFor(m => node)</li>
}
</ul>
#Html.Partial("_LoginPartial")
</div>
And i display it with
#Html.MvcSiteMap().Menu("MyMenu")
I'm trying to get nested menus to work. As i have some dropdown menu items that havesub catergories. For example
--Main Menu
------Sub Menu
What would be the best way to accomplish this?
The menu templates are broken up into 3 separate parts, so you will need to override each part (not just the main one) by specifying the additional templates inside of your custom one. See this answer for a set of templates to get you started. Then it is just a matter of modifying the HTML the way you would like.

Adding element ID to navigation items in Grails Platform Core Navigation API

Is it possible to add HTML attributes such as id or class to each menu item generated by the Grails Platform Core Navigation API?
Perhaps something similar to:
home(controller: 'home', action:'index', titleText:'Home', elementId: 'navHome')
I am writing some functional tests which use the generated links. However, the link text (and possibly the URLs) might change. Using an ID would make the tests easier to maintain.
The Navigation API provides the ability to add additional values via the data map and custom menu item rendering.
Example:
Step 1
Add the data map to the menu item definition in config/AppNavigation.groovy.
home(controller: 'home', action:'index', titleText:'Home', data: [elementId: 'navHome'])
Step 2
Reference the data map using item.data.* in the GSP file.
<nav:primary scope="some scope" custom="true">
<li>
<p:callTag
tag="g:link"
attrs="${linkArgs + [class:active ? 'active' : ''] + [elementId:item.data.elementId]}"
><nav:title item="${item}"/></p:callTag>
</li>
</nav:primary>
This will result in the following HTML:
<ul class="nav primary">
<li>
Home
</li>
</ul>
See the nav:menu tag documentation in the Navigation API documentation for more information.

Use Bootstrap Navbar choice in controller?

All, I'm trying to use the Bootstrap Navbar user choice to control the filtering of posts shown to the user.
The model includes an 'expired' field which is a date-time type.
Three choices are: All (no filtering), Open (show only open issues) and Closed (show closed).
Is there a way to do this without defining three different index.html.erb variants (DRY problem). The filter should show only closed issues if #post.expired < Time.now .. etc.
Stated alternately - can controller 'know' what the user chose, although Navbar, as i am using it, is simply a fancy navigation toolbar?
Thanks for any advice.
Typically this is done by including a parameter in the request, and looking for that parameter in the controller. The bootstrap navbar uses regular anchor links so you should be able to add parameters easily to them (modified example from the doc):
<div class="navbar">
<div class="navbar-inner">
<a class="brand" href="/some_url">List</a>
<ul class="nav">
<li>All</li>
<li>Open</li>
<li>Closed</li>
</ul>
</div>
</div>
You can read the filter parameter in the controller by accessing the value of params[:filter].

How do I select similar-contented items in multiple lists when any one is selected?

I am using HTML4.01 Strict, CSS3 and the latest JQuery.
I have three identical lists in one page - one acts as a menu bar, the other two are smaller and appear on either side of the main page content.
I would like it so that when any single option in one list is selected, it also selects the same option in the other two lists.
'Selection' in this case means the application of the class "active_tab" [via .addClass("active_tab") ]
The list:
<ul id="lt-menu" class="shift_menu">
<li class="li_tab">Home</li>
<li class="li_tab">News</li>
<li class="li_tab">Info</li>
<li class="li_tab">Download</li>
<li class="li_tab">Contact</li>
<li class="li_tab">Shop</li>
</ul>
I have been attempting to use something along these lines -
$(".tab, .li_tab").click(function() {
$(".active_tab").removeClass("active_tab");
$("li".contains(this)).addClass("active_tab");
});
But with no luck so far.
I'm pretty new to JQuery, so any help at all would be much appreciated.
Il tried this with 3 copies of your list (I just change the ID), and it works:
$(".tab, .li_tab").click(function() {
//Disable current selection
$(".active_tab").removeClass("active_tab");
// We get the index of the <li> in the current list
// Each <li> has to be to the same index in the other lists
var index = $(this).index();
// We add the 'active_tab' class to all <li> with the same index
// Assume that all lists have the 'shift_menu' class, of modify the selector
$('.shift_menu').find('li:eq(' + index + ')').addClass("active_tab");
});
Hope it works for you...

Resources