Jump to content

Add a new action button to page edit screen


Ivan Gretsky
 Share

Recommended Posts

Good day!

Sorry for not finding it if it is already out there in the forums. I did try, but probably do not even know the right words to put into a searchbar.

I need to put a button in the page edit screen of the admin for a specific template. When a user clicks on that, he should be led to creation of a new page, related to the one he is on.

Making it more of a real-life situation: it is a company page with a template "company" under "company-root".  I need to place a "Create new classified Item" button on the edit screen for every saved page with that template  When a user clicks on that he should be led to creation screen for a new page with "classified-item" template to be stored under "classified-root" template.

I guess this should be a module which hooks into some method... But I am in the beginning of my journey to PW module-making, so please give me some (preferably clear and simple) directions.

Link to comment
Share on other sites

@Ivan,

Part of my stock toolkit when building sites is a "save action".

It is a simple way to run some action when the user saves; they select the save action, and click save, and the action runs. It usually hooks into SaveReady.

It could be anything from calculating/validating/correcting/filling in blank fields to things like deleting children, renaming assets (images, files) etc..

I usually use a special select field for this, but you could use a checkbox. If I needed to create the functionality you are describing right at this moment, i would make the save action a checkbox and then have next to it After save: Create new classified Item;

your module code would then simply create a new page under the specified parent and redirect the user to that edit page...

  • Like 1
Link to comment
Share on other sites

Yes, I understand what you are suggesting. Thank you!

But this solution seems to me a bit "clumsy". I think it would be more convinient for the client to have a tab like "Children" with a list or related classified items and a big green button "Add new classified item". When user pushes that button he should be send to a new page creation screen with "classified-item" template chosen under specified root page AND company page field set to the company page he came from.

Do you have an idea how this could be done?

Link to comment
Share on other sites

maybe a part could be done by restricting children - parent relation via family settings? Template for parent that only allow a single Template for children. That way, when adding a child, it has the right Template and the right position. Only thing left is the population of your field.

  • Like 1
Link to comment
Share on other sites

Yes, but I do not know how to insert a tab with classified items and a button in the first place ))  Could you help on this too?

Oh, no haven't done those things.

Maybe there are already modules out that do similar things where one can study the code?

Link to comment
Share on other sites

Some examples from some of my modules - only because I quickly know where I have used these things  :)

I'll link to the hook, so obviously also view the called function as well.

New tab

https://github.com/adrianbj/ProcessRedirectIds/blob/master/ProcessRedirectIds.module#L104

$this->addHookAfter('ProcessPageEdit::buildForm', $this, 'addTab');

Add content to existing tab

https://github.com/adrianbj/BatchChildEditor/blob/master/BatchChildEditor.module#L100

$this->addHookAfter('ProcessPageEdit::buildFormChildren', $this, 'addChildTabContent');

Obviously with this, "buildFormChildren" could be replaced with buildFormSettings etc.

Hope that helps.

  • Like 5
Link to comment
Share on other sites

But this solution seems to me a bit "clumsy". I think it would be more convenient for the client to have a tab like "Children" with a list or related classified items and a big green button "Add new classified item". When user pushes that button he should be send to a new page creation screen with "classified-item" template chosen under specified root page AND company page field set to the company page he came from.

Do you have an idea how this could be done?

yes - this is a texbook page table scenario...

  • Like 1
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...