Jump to content

Remove "New" Button from Pages List-View


didhavn
 Share

Recommended Posts

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!

Unbenannt.JPG

Link to comment
Share on other sites

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.

  • Like 1
Link to comment
Share on other sites

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.

  • Like 2
Link to comment
Share on other sites

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

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

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

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.

  • Like 4
Link to comment
Share on other sites

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.

  • Like 1
Link to comment
Share on other sites

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.

  • Like 1
Link to comment
Share on other sites

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

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.

  • Like 2
Link to comment
Share on other sites

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

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!

Unbenannt.JPG

Link to comment
Share on other sites

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

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.

  • Like 1
Link to comment
Share on other sites

  • 1 year later...

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...