RE: Remove items from personal bar menu in 7.2

Erik Lillegraven, modified 6 Years ago. Junior Member Posts: 27 Join Date: 6/6/11 Recent Posts
Hi,

Does anyone know how to remove a menu item in the personal bar in 7.2 ?

For example remove "My Submissions" and "My Workflow Tasks". Is it possible?

Ref. https://github.com/liferay/liferay-portal/blob/master/readme/BREAKING_CHANGES.markdown#move-the-user-menu-out-of-the-product-menu

Thanks
Vivek Mehta, modified 6 Years ago. Junior Member Posts: 48 Join Date: 4/7/19 Recent Posts
Hi Erik,
I doubt that you can acheive this for the administrator. But for any normal user you can acheive this by simply defining  permissions in the roles section. Just follow these steps :-
i )    Go to Control Panel.
ii )  Open Roles.
iii)  Select the desired Role ( i.e, if the user for whom you want to hide  the "My Submissions" and "My Workflow Tasks" options has the role "Client Member" then select "Client Member") .
iv ) Now go to the "define permissions" menu.
v)   There you will see "My Account" Option . Open it.
vi) Now enable or disable the access from there as your requirement.
Erik Lillegraven, modified 6 Years ago. Junior Member Posts: 27 Join Date: 6/6/11 Recent Posts
The "My Account" is removed in v7.2, so that is not possible. Can't find any other permission neither which has any impact on this.
thumbnail
Juan Miguel Imaz, modified 6 Years ago. New Member Posts: 7 Join Date: 4/30/14 Recent Posts
For the administrator you can play with a litte of css to "remove" the undesidered elements.
Erik Lillegraven, modified 6 Years ago. Junior Member Posts: 27 Join Date: 6/6/11 Recent Posts
Thanks for your reply.
I'm afraid there is no id or class attributes in the html that can be used to pick specific menu (list) elements to be hidden, so this approach seems not to be an option. 
Vivek Mehta, modified 6 Years ago. Junior Member Posts: 48 Join Date: 4/7/19 Recent Posts
Rather try searching for the jsp files inside the   " liferay-portal-> tomcat -> webapps -> ROOT -> html " which contains this portlet or menu( It is gonna take some effort in searching ). Then you can create the hook and make changes in that jsp file by importing the custom jsp files from liferay hook configurations. Then from there simply delete the portionof code which is responsible for showing that menu ( My submissions, My workflow taks, etc.).  I have done this few times. It will work for you too.
Erik Lillegraven, modified 6 Years ago. Junior Member Posts: 27 Join Date: 6/6/11 Recent Posts
The jsp file uses a tag to render the Personal Menu:
<liferay-product-navigation:personal-menu     expanded="<%= true %>"     label="<%= userAvatar %>" />

This tag gets all classes implementing "PersonalMenuEntry", so it's easy to add a menu-entry by creating such a class, but not to remove one.

The logic lies within these Liferay classes which have a method to decide if to show its menu entry or not. But I don't know how to override these classes. They are not like service classes which you can extend and give a higher "service.ranking".
Vivek Mehta, modified 6 Years ago. Junior Member Posts: 48 Join Date: 4/7/19 Recent Posts
You will need to do some hit and trials here. But be sure to make changes only in the hook so that the original jsp file doesnt gets affected.
Dmitry Oshkalo, modified 6 Years ago. New Member Posts: 4 Join Date: 9/14/19 Recent Posts
If you want to just get rid of  some menu items in the personal bar, it will be much easier to use component blacklist:
https://portal.liferay.dev/docs/7-1/user/-/knowledge_base/u/blacklisting-osgi-modules-and-components
For instance, to remove "My Workflow Tasks" open Conrol Panel, then navigate to Configuration -> System settings, then click on Module Container icon in Platform category. Then select Component blacklist from the list and specify 
com.liferay.portal.workflow.task.web.internal.product.navigation.personal.menu.MyWorkflowTaskPersonalMenuEntry 
as a component's name. After you click on Update button, the item will go away from the personal bar.You may find out the names of the components corresponding to each default menu item by using the gogo console like this.
scr:list | grep PersonalMenuEntry 
Of course, if you want to implement some additional functionality over the menu items, you should follow Jan's advice and override MVCResourceCommand.
Erik Lillegraven, modified 6 Years ago. Junior Member Posts: 27 Join Date: 6/6/11 Recent Posts
Thanks, blacklisting works fine.But it would also be  nice if one could override some of the PersonalMenuEntry classes and set the logic in the isShow() method with our own code.
Dmitry Oshkalo, modified 6 Years ago. New Member Posts: 4 Join Date: 9/14/19 Recent Posts
I can't say this is the best way of solving the problem (since I'm not so confident with OSGi), but at least it works.
As far as I understand, since every personal menu entry is a separate component implementing PersonalMenuEntry interface, which determines isShow(...) as a default method and just returns "true", and none of the components overrides this method, it's useless to override PersonalMenuEntry using service ranking (you'll just get duplicated entries). The proposed solution is to replace an original component with a custom one. By replacing I mean deactivating the original component when the custom one is activated and vice versa.
This post should be helpful: https://liferay.dev/blogs/-/blogs/extending-osgi-components
The custom component for MyWorkflowTaskPersonalMenuEntry looks like this:
@Component(immediate = true, 
property = { 
		"product.navigation.personal.menu.entry.order:Integer=500",
		"product.navigation.personal.menu.group:Integer=200"
	}, service = PersonalMenuEntry.class)
public class CustomMyWorkflowsTaskPersonalMenuEntry extends BasePersonalMenuEntry {

	private final static String COMPONENT_NAME = "com.liferay.portal.workflow.task.web.internal.product.navigation.personal.menu.MyWorkflowTaskPersonalMenuEntry";

	private BundleContext _bundleContext;
	
	private ComponentDescriptionDTO _desc;

	@Reference
	private ServiceComponentRuntime _serviceComponentRuntime;

	@Activate
	public void activate(BundleContext bundleContext) throws InvalidSyntaxException {
		_bundleContext = bundleContext;
		_deactivateOriginalComponent();
	}
	
	@Deactivate
	public void deactivate() throws InvalidSyntaxException {
		_activateOriginalComponent();
		_bundleContext = null;
	}

	private void _deactivateOriginalComponent() throws InvalidSyntaxException {
		if (_bundleContext == null) {
			return;
		}
		
		Collection<servicereference<personalmenuentry>&gt; componentMenuEntries = _bundleContext
				.getServiceReferences(PersonalMenuEntry.class, "(component.name=" + COMPONENT_NAME + ")");
		
		for(ServiceReference<personalmenuentry> ref : componentMenuEntries) {
			Bundle bundle = ref.getBundle();
			_desc = _serviceComponentRuntime.getComponentDescriptionDTO(bundle, COMPONENT_NAME);
			_serviceComponentRuntime.disableComponent(_desc);
		}
	}
	
	private void _activateOriginalComponent() throws InvalidSyntaxException {
		if (_desc != null) {
			_serviceComponentRuntime.enableComponent(_desc);
		}
	}
	

	@Override
	protected String getPortletId() {
		return PortletKeys.MY_WORKFLOW_TASK;
	}

	@Override
	public boolean isShow(PortletRequest portletRequest, PermissionChecker permissionChecker) throws PortalException {
		// your logic here...
	}
}
</personalmenuentry></servicereference<personalmenuentry>


You also may override getLabel() and other methods as you like. After you deploy this component, the original MyWorkflowTaskPersonalMenuEntry will be replaced, if your version of isShow() returns true, or none will be displayed otherwise. After you remove the custom component, the original one should be displayed as usual.
thumbnail
Fernando Paz, modified 3 Years ago. New Member Posts: 11 Join Date: 9/16/16 Recent Posts

IMO, the is a rol name "User" that is asigned to all authenticated users.  There you can follow the instruction by @Vivek Metha enable or disabled the "Access in Personal Menu" Permission.