didhavn Posted January 30, 2017 Share Posted January 30, 2017 Hey All. I need some help with a problem relating to users permissions to create pages and selectively remove a "new" button. I have a container page called "Sektionen" to keep Sektions of pages. These sections are created within different pages via a pagetable field. Now I want to change the way new sections can be created in a way that they can ONLY be created via the pagetable-field, not via the "new" button in the pages tree (see screenshot - this button should be removed). I think I can not change this in the templates settings and wanted to ask if anybody of you has an idea how to accomplish that? Thanks a lot! Link to comment Share on other sites More sharing options...
kongondo Posted January 30, 2017 Share Posted January 30, 2017 Not an answer to your question. Just pointing out a coincidence that an almost identical question was asked within the hour. Anyway, I am cross-referencing the two threads: Link to comment Share on other sites More sharing options...
adrian Posted January 31, 2017 Share Posted January 31, 2017 I think you can probably do what you want by hooking into: ProcessPageListActions::getActions but unless you have a need to keep the Sektionen branch visible, I think the easiest option is to move it under the Admin branch where non-superusers won't have access to edit it. 1 Link to comment Share on other sites More sharing options...
Robin S Posted January 31, 2017 Share Posted January 31, 2017 5 hours ago, adrian said: I think the easiest option is to move it under the Admin branch where non-superusers won't have access to edit it IMHO this should be the default behaviour of a PageTable field. Having the PageTable pages as children of the page is confusing for editors and I've never understood the reasons why that should happen as the default. 2 Link to comment Share on other sites More sharing options...
PWaddict Posted January 31, 2017 Share Posted January 31, 2017 16 hours ago, adrian said: I think the easiest option is to move it under the Admin branch where non-superusers won't have access to edit it. But if it moved under the Admin branch the urls of the pages created via PageTable will include the /admin/ or no? Link to comment Share on other sites More sharing options...
adrian Posted January 31, 2017 Share Posted January 31, 2017 Just now, PWaddict said: But if it moved under the Admin branch the urls of the pages created via PageTable will include the /admin/ or no? Yes - so it's only an option if you don't want the pages accessible directly, which is usually (although not always) the case with PageTable child pages. Link to comment Share on other sites More sharing options...
PWaddict Posted January 31, 2017 Share Posted January 31, 2017 16 hours ago, adrian said: I think you can probably do what you want by hooking into: ProcessPageListActions::getActions. So I guess the only option is this but unfortunately I don't have the knowledge to do that hooking. Can you help if it's easy for you? All I want is to remove the "New" button from a specific page id. Link to comment Share on other sites More sharing options...
adrian Posted January 31, 2017 Share Posted January 31, 2017 Something like this in your /site/init.php $this->addHookAfter('ProcessPageListActions::getActions', null, function(HookEvent $event) { $p = $event->arguments[0]; $actions = $event->return; if($p->template->name == 'aaa') { unset($actions['edit']); } $event->return = $actions; }); Just replace the $p->template->name with your condition - whether it's a real template name, or change to $p->parent->id to get the parent of the page table items - whatever works best for you. 4 Link to comment Share on other sites More sharing options...
didhavn Posted January 31, 2017 Author Share Posted January 31, 2017 Hey all. Thanks a lot for your effort to help! Adrian, your solution works just perfect, thanks a lot! 1 Link to comment Share on other sites More sharing options...
PWaddict Posted January 31, 2017 Share Posted January 31, 2017 1 hour ago, adrian said: Something like this in your /site/init.php $this->addHookAfter('ProcessPageListActions::getActions', null, function(HookEvent $event) { $p = $event->arguments[0]; $actions = $event->return; if($p->template->name == 'aaa') { unset($actions['edit']); } $event->return = $actions; }); Just replace the $p->template->name with your condition - whether it's a real template name, or change to $p->parent->id to get the parent of the page table items - whatever works best for you. THANK YOU Problem solved. 1 Link to comment Share on other sites More sharing options...
adrian Posted January 31, 2017 Share Posted January 31, 2017 Just now, PWaddict said: THANK YOU Problem solved. Just be aware that this doesn't prevent someone from editing it if they manually enter the edit url. To prevent that you would need to hook into: Page::editable, but keep in mind that this will cause problems with the PageTable field being able to edit this pages (unless you also account for that), so I think what you have is likely the best compromise. 1 Link to comment Share on other sites More sharing options...
PWaddict Posted January 31, 2017 Share Posted January 31, 2017 33 minutes ago, adrian said: Just be aware that this doesn't prevent someone from editing it if they manually enter the edit url. To prevent that you would need to hook into: Page::editable, but keep in mind that this will cause problems with the PageTable field being able to edit this pages (unless you also account for that), so I think what you have is likely the best compromise. I removed the "new" button not the edit one. Clients edit what they see in front of them so I doubt they will try to find that specific "new" url and enter it manually instead of just going to the PageTable page. I will also use your Restrict Tab View module to hide the children tab to avoid adding pages from there too. Do you know if it's possible to also prevent loading the children pages on the page tree from that specific parent? The client should be able to see the total number of children pages next to it's parent but when they click on that parent it will NOT load the children pages. Link to comment Share on other sites More sharing options...
adrian Posted January 31, 2017 Share Posted January 31, 2017 Sorry, I meant "new" whenever I wrote "edit". I spaced for a minute there 1 minute ago, PWaddict said: Do you know if it's possible to also prevent loading the children pages on the page tree from that specific parent? This starts getting a little more complicated. Have a read here: You can probably cobble something together from that thread and some of my linked gists. 2 Link to comment Share on other sites More sharing options...
PWaddict Posted January 31, 2017 Share Posted January 31, 2017 14 minutes ago, adrian said: Sorry, I meant "new" whenever I wrote "edit". I spaced for a minute there This starts getting a little more complicated. Have a read here: You can probably cobble something together from that thread and some of my linked gists. Ok thanks I will check them out. Link to comment Share on other sites More sharing options...
didhavn Posted February 1, 2017 Author Share Posted February 1, 2017 Hey. I have a follow up question to this one: Unfortunately, it is still possible for the user, to add pages via the "Children" tab in a page (see screenshot). I want to asure, that the user can create these Section-Pages only via the pagetable and not from somewhere else. Do you know how to hook into this tab and remove/disable the button? Thanks a lot! Link to comment Share on other sites More sharing options...
adrian Posted February 1, 2017 Share Posted February 1, 2017 That shouldn't be hard, but what about just hiding the Children tab altogether using this module: http://modules.processwire.com/modules/restrict-tab-view/ Link to comment Share on other sites More sharing options...
didhavn Posted February 1, 2017 Author Share Posted February 1, 2017 Smart idea However, this module only works for non-superusers. I want to achieve this behaviour for all users including superuser. I just dont want anybody do mess with these pages. You have a hint for me how to remove/disable this button OR remove the children tab for all users? Link to comment Share on other sites More sharing options...
didhavn Posted February 1, 2017 Author Share Posted February 1, 2017 Ok, fixed it using your RestictTabView module and just removed the two 71: if($this->user->isSuperuser()) return; ... 96: if($this->user->isSuperuser()) return; cases Thanks a lot!! 1 Link to comment Share on other sites More sharing options...
adrian Posted February 1, 2017 Share Posted February 1, 2017 No problem - don't forget to watch out for upgrades to the module Btw, another approach to I think what you are looking for: Currently it only works when the children and direct child pages, but it would be easy to customize to a different branch parent. Maybe you prefer the approach you have and I think I agree with you for your use case, but this is just another option, maybe for a different project. 1 Link to comment Share on other sites More sharing options...
didhavn Posted February 1, 2017 Author Share Posted February 1, 2017 Great idea, this should be included (as default) into the module as it would fix almost all issues I had with pagwtables. Thanks! 2 Link to comment Share on other sites More sharing options...
webhoes Posted November 4, 2018 Share Posted November 4, 2018 I tried this for a site, but the new button is still visible. The template studbook can have a child with template animal. I have resticted a per page right edit rights for the studbook. On that page you can use the tab to add a new animal. But all people can see the tree and now with every studbook there is a option for new. If this is not visible, only people with the right page rights you can add a child from the page... I am using the current dev version of pw. $this->addHookAfter('ProcessPageListActions::getActions', null, function(HookEvent $event) { $p = $event->arguments[0]; $actions = $event->return; if($p->template->name == 'studbook') { unset($actions['new']); } $event->return = $actions; }); 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