Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#8752: Hide/show menu items on the frond-end #8753

Open
wants to merge 2 commits into
base: 1.10.x
Choose a base branch
from

Conversation

gdessimoneinvalle
Copy link

@gdessimoneinvalle gdessimoneinvalle commented Jan 26, 2024

Fixes #8752

We propose the solution we have developed to the community's attention

image

Giuliano Dessimone added 2 commits January 26, 2024 15:08
# Conflicts:
#	src/Orchard.Web/Core/Navigation/Services/DefaultMenuProvider.cs

if (!Services.Authorizer.Authorize(Permissions.CreateContent, contentItem, T("Couldn't clone content")))
if (!Services.Authorizer.Authorize(Permissions.ViewContent, originalContentItem, T("Couldn't open original content")))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain why these permissions are changed?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We started from a fork version of LaserOrchard which already has these changes, it is a part of code that I did not write but which I had to integrate to remain aligned with the version we started from. Ours mod is just a proposal, which unfortunately integrates changes that were not made by us, if too different from the code, as far as I'm concerned it can be rejected entirely

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes are from the dev branch.

@@ -21,6 +21,7 @@
using Orchard.Core.Contents.Settings;
using Orchard.Data;
using System.Web.Routing;
using Orchard.Time;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove

@@ -27,7 +28,23 @@ public class DefaultMenuProvider : IMenuProvider {
.Where(x => x.MenuId == menu.Id)
.List();
}
var menuParts = _menuPartsMemory[menu.Id];
var menuParts = _menuPartsMemory[menu.Id].ToList<MenuPart>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ToList is unnecessary. Change the type of the dictionary instead.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless you think the enumeration is executing the query again.

var menuParts = _menuPartsMemory[menu.Id].ToList<MenuPart>();

//List of hidden items
var menuPartsHidden = _contentManager
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The menus are already loaded from database, why do another query? You can just filter in Linq.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried but the code didn't return the list I expected, this is the committed code I added in my version

        //An attempt to optimize the code above but unsuccessful
        //var menuParts = _contentManager
        //    .Query<MenuPart, MenuPartRecord>()
        //    .Where(x => x.MenuId == menu.Id && x.VisibleAtFrontEnd && !_contentManager
        //    .Query<MenuPart, MenuPartRecord>()
        //    .Where(x => x.MenuId == menu.Id && !x.VisibleAtFrontEnd)
        //    .List().Where(w => x.MenuPosition.StartsWith(w.MenuPosition)).Any())
        //    .List().ToList();

@sebastienros
Copy link
Member

So it's really just to be able to hide a menu item without deleting it? So just "Visible" or "Hidden"?

@giannik
Copy link
Contributor

giannik commented Feb 5, 2024

Please see my comments in related issue #8752

/// </summary>
/// <param name="menu">The menu item</param>
/// <param name="value">Show->true or Hide->false</param>
private void VisibleAtFrontEnd(MenuPart menu, Boolean value) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this method be here? It's working on MenuPart, but this controller is the one for ContentItems

@BenedekFarkas
Copy link
Member

Wouldn't publish/unpublish be able to achieve the same functionality (with hopefully less code)?

@BenedekFarkas BenedekFarkas changed the title 8752 new feature hide show frontend #8752: Hide/show menu items on the frond-end Apr 18, 2024
Copy link
Member

@BenedekFarkas BenedekFarkas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gdessimoneinvalle @MatteoPiovanelli-Laser please see #8807 for a simpler implementation based publishing/unpublishing menu items. Does this satisfy your requirements?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants