formwork
formwork copied to clipboard
Add the possibility to duplicate pages
This pull request adds a "Duplicate Page" feature to the CMS, allowing users to create a copy of an existing page through the panel UI. The implementation includes backend logic for duplicating a page, frontend modal integration, new route and permissions checks, and UI updates to expose the feature in both the page editor and the page tree.
The most important changes are:
Backend functionality:
- Added
isDuplicable()andduplicate()methods to thePageclass, enabling logic to check if a page can be duplicated and to perform the duplication, including copying content and updating fields like slug and title. [1] [2] [3] - Added a new controller action
duplicateinPagesControllerto handle the duplication request, validate input, and redirect the user to the new page's editor. Also added a helper methodduplicatePagefor the duplication process and content history update. [1] [2] - Registered a new POST route
panel.pages.duplicatefor the duplication endpoint.
Frontend and UI integration:
- Added a new modal definition
duplicatePage.yamlfor collecting title and slug when duplicating a page. - Updated the page editor and page tree views to include a "Duplicate Page" option in the actions dropdown, with permission checks and disabled state if the page is not duplicable. [1] [2]
- Registered the duplicate page modal in relevant views. [1] [2]
Frontend logic:
- Updated the TypeScript
pages.tscomponent to handle opening the duplicate modal, pre-filling the title and slug fields using the original page title, and generating a slug automatically. [1] [2] [3]
Localization:
- Added new translation strings for the duplicate page feature.
You are on a roll with all these PR recently :) And I see you started some work with plugins too.. That's really exciting! Thank for this great CMS