Published: October 10, 2024
Cloning Content in a LocalGov Drupal website
This week as part of my "Editor Experience" work for LocalGov Drupal, I worked on creating a feature to allow editors to clone pages of their sites.
Need LocalGov Drupal services? Give Big Blue Door a shout.
I spent last week and this week working mostly on editor experience issues for LocalGov Drupal. Last week was small bug fixes and features, and this week I spent my time getting a new module created that would do two things:
- Allow site owners decide what content types could have their content cloned, and
- Allow site editors to then clone pages from those content types.
This is a feature request that councils have been asking for for quite a while.
Why Clone Content?
Often on a council website you could have a lot of events and you might want to have all the same info for the events, but a different date, image, and signup link. Being able to clone a default event is a great time saver in this case.
You might also have a number of landing pages which can be time consuming to create - banner, related links, quick links, etc. In terms of consistency it's very handy to be able to create a template landing page, then clone it each time you need a new one.
How does it LocalGov Replicate module work?
It's quite simple. You install the LocalGov Replicate module - available via composer require localgovdrupal/localgov_replicate
. Then go to the settings page admin/config/content/localgov-replicate
, choose what content types you want editors to be allowed to replicate.
Now when you visit any nodes of these types, there will be a new tab (besides the "View | Edit | Delete" tabs) called "Replicate". When you click on that it will:
- Create a copy of the current page, and
- Bring you to that new version of the page so you can start editing it, and
- Leave the new page unpublished until you are ready to publish it.
Node Clone Vs Entity Clone Vs Replicate
We chose the Replicate module to use for this feature. Node clone will only clone nodes and we might in the future want to clone more entities, such as custom entities.
Entity clone will clone entities, but would clone the each entity on the page at the same time.
Replicate is an API-first module, without a UI (you can install Replicate UI if you want), but gives us full control over everything we want to do with our cloning feature.
Is it feature complete?
Nope, not by a long shot.
I have one major issue with it at the moment, which is that the "Replicate" tab is showing up for all content types no matter what you choose on the settings page.
Once I get that solved, I need to see what happens when you clone nodes with media and other entities in them. I guess we want to reference media, taxonomy, etc, but we want to clone paragraphs. Then we've the trickier question of reusable paragraphs in our "Page Components" module which I guess we also want to reference rather than clone, so if we update for example an address, it will update everywhere.
Thanks to Big Blue Door for sponsoring my time to work on this.