Static Pages duplication

Hello,
I have made a plugin to allow to duplicate content (blocks/properties and content) from a static page to another. If there is a multi-site, then one need to create the page in all sites and then copy the contents from src to dst page.

What I don’t know is if the way that I implemented the feature is the correct/best one so I have the following questions:

1) How can I add a button to the static pages toolbar (side by side with the save button)?
I know I can duplicate the file in my plugin/theme or append the button via JavaScript but I’m looking for some hook/event so my plugin does not break/ get broken with future RainLab.Pages updates. Check image bellow.

2) Is there a easy way to create a static page by code “new …\Pages\Classes\Page()” maintaining the correct function of the Pages plugin?

3) Can I rename the name of the file (blabla.htm) from php code of an existing static page?

I hope someone have some insights about this because I really could’t find anyting about this in my searches.

Best regards,
Domingos

Summary

This text will be hidden

For this, you could include a view event. There are some places where it happens in plugins already using the fireViewEvent method. For example:

<?= $this->fireViewEvent('rainlab.user.view.extendPreviewToolbar', [
    'record' => $formModel
]); ?>

Then the example usage:

Event::listen('rainlab.user.view.extendPreviewToolbar', function (
    (RainLab\User\Controllers\Users) $controller,
    (RainLab\User\Models\User) $record
) {
    return $controller->makePartial('~/path/to/partial');
});
1 Like