![](https://linuxpunx.com/wp-content/uploads/2024/07/simplifying-content-duplication-with-quick-node-clone-module-in-drupal.jpg)
If you’re a marketer, you know how much content cloning can simplify your life. It lets you duplicate blog posts, landing pages, articles, product listings, and forum posts effortlessly.
If you’re familiar with Drupal, you should know that nodes are fundamental content entities that represent individual pieces of content on a site. Creating similar content nodes in Drupal can be time-consuming, especially when you have to duplicate them manually.
Fortunately, there’s a solution: the Quick Node Clone module. In this blog post, we’ll explore how this handy module can streamline your content creation process in Drupal.
What is the Quick Node Clone Module
Contents
The Quick Node Clone module allows Drupal users to swiftly duplicate existing nodes with just a few clicks. This module can save you time and effort by eliminating the need to recreate content from scratch.
How to Install the module
Getting started with the Quick Node Clone module is straightforward. Simply follow these steps:
- Download the module from Drupal.org or use Composer to install it.
- Enable the module in the Drupal administration interface.
- Clear the cache for the changes to take effect.
Configuring the module
Once the module is installed, you can customize its settings to suit your needs.
- Text to prepend to title
The text we enter in this field will be prepended to the title of the cloned node.
This will be seen on the node clone page.
- Clone publication status of original
If it’s checked then the publication status will be cloned from the Original node that we clone.
If Unchecked the publication status will be cloned from the “default publish status of the content type” of that particular node.
- Exclusion list
If you don’t want some field values to be cloned then you can choose the particular content type and exclude any field.
This module also supports ‘paragraphs’, allowing us to exclude any paragraph field from being cloned, similar to nodes.
How to Use Quick Node Clone
Using the Quick Node Clone module is simple:
- Navigate to the node you want to duplicate.
-
Click on the “Clone” button, depending on your Drupal configuration.
- Optionally, make any necessary changes to the cloned node.
- Save the cloned node, and you’re done!
Permissions:
This module provides a set of permissions. For any content type, we can grant permission to clone its nodes.
Additionally, there’s the “Administer Quick Node Clone Settings” permission, granting access to the module’s configuration page at /admin/config/quick-node-clone.
Hooks provided by the module:
1. hook_cloned_node_alter()
Example Usage
Let’s consider a practical example where we want to modify certain properties of the cloned node:
/**
* Implements hook_cloned_node_alter().
*/
function mymodule_cloned_node_alter($cloned_node, $original_node) {
// Change the title of the cloned node.
$cloned_node->setTitle('Modified Title');
// Check if the cloned node has a specific field and update its value.
if ($cloned_node->hasField('field_example')) {
$cloned_node->set('field_example', 'New Field Value');
}
}
- mymodule should be replaced with the machine name of your custom module.
- $cloned_node represents the cloned node object that you can modify.
- $original_node refers to the original node being cloned, providing context for your alterations.
2. hook_cloned_node_paragraph_alter()
Example Usage
Let’s consider an example scenario where we want to update the value of a specific paragraph field during the cloning process:
/**
* Implements hook_cloned_node_paragraph_field_alter().
*/
function mymodule_cloned_node_paragraph_field_alter($paragraph, $field_name, $settings) {
// Check if the paragraph has a field named 'field_place' and update its value.
if ($paragraph->hasField('field_place')) {
$paragraph->set('field_place', 'New Changed Place');
}
}
- mymodule should be replaced with the machine name of your custom module.
- $paragraph represents the cloned paragraph entity that you can modify.
- $field_name indicates the name of the paragraph field being processed.
- $settings provides additional information about the field.
Final thoughts
The Quick Node Clone module is a valuable tool for Drupal users looking to streamline their content creation process. This module can save you time and effort by simplifying the duplication of nodes, allowing you to focus on more important tasks. Give it a try on your Drupal site and experience the benefits firsthand!