DrQuincy Posted April 30 Share Posted April 30 When a user goes to a page in the CMS that they don't have permission to access you get two messages: ProcessWire: You don't have access to edit The process returned no content. How can I use hooks to override these messages? Ideally for point 2, I'd like to use HTML. Thanks. Link to comment Share on other sites More sharing options...
gebeer Posted April 30 Share Posted April 30 I'd take a different approach and use hooks Page::viewable and Page::editable in templates/admin.php to either throw a 404 or to redirect to some default page they can view. In either case you can add a message or error that will be shown at the top of the page. 1 Link to comment Share on other sites More sharing options...
DrQuincy Posted May 1 Author Share Posted May 1 Thanks for the suggestion. It's slightly different in this instance since there are additional items in the admin that appear in the menu, which I can't remove, and it would just make it look like they're broken if they 404. I was hoping instead to simply override the text of these to make the user experience make more sense: ProcessWire: You don't have access to edit The process returned no content. Even something as simple as a translation would be better: You don't have permission to view or edit anything on this page This page is for administrators only. Please click here to go back to the main admin page. Is that easy to do? Link to comment Share on other sites More sharing options...
gebeer Posted May 1 Share Posted May 1 18 minutes ago, DrQuincy said: and it would just make it look like they're broken if they 404 I proposed to either 404 or redirect. So if you redirect to the main admin page and add a message before you redirect, the user doesn't even need to click anywhere and gets there automatically. Better UX IMO. 20 minutes ago, DrQuincy said: there are additional items in the admin that appear in the menu, which I can't remove Which items would that be? You can setup your roles/permissions in a way that users only see the menu items for pages/processes they have access to. If your users get access to the page tree, you can use hooks that utilize Page::viewable to remove those pages from the tree that they should not see. 23 minutes ago, DrQuincy said: Even something as simple as a translation would be better: 23 minutes ago, DrQuincy said: Is that easy to do? You'd have to activate language support (if you haven't already) and then in the settings for each language search through the core translation files to find those strings and then overwrite them. 1 Link to comment Share on other sites More sharing options...
DrQuincy Posted May 1 Author Share Posted May 1 Thank you. I totally agree with you but… The reason I'm doing it this way is I'm using the https://github.com/Toutouwai/CustomAdminMenus plugin — and this is unaware of page permissions. EDIT: I've realised this will do the job. It's not quite what I was after but it's a bit of an edge case anyway and only takes a minute to implement. wireLangReplacements([ 'The process returned no content.' => 'This page is either for administrators only or it doesn’t exist. Please go back and choose another page.', ]); Thanks for your help. 1 Link to comment Share on other sites More sharing options...
gebeer Posted May 1 Share Posted May 1 That's a quick solution, indeed ? EDIT: I never used that module CustomAdminMenus. Just saw that it supports hooks to hide menu items based on user role: https://github.com/Toutouwai/CustomAdminMenus?tab=readme-ov-file#showinghiding-menus-according-to-user-role 1 Link to comment Share on other sites More sharing options...
DrQuincy Posted May 2 Author Share Posted May 2 Nice find, thanks. ? 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