Advertising sustains the DA. Ads are hidden for members. Join today

Contributed module documentation

Quick Node Clone

Last updated on
15 March 2025

Introduction

The Quick Node Clone module adds a "Clone" tab to a node. When selected, a new node is created and fields from the previous node are populated into the new fields.

This is potentially duplicate work of Node Clone (https://www.drupal.org/project/node_clone), but as of release they don't have a stable D8 version and this code was created for a project from scratch in a reusable manner. This is focused on supporting more variety in field types than core's default cloning.

Future @TODO: Support more than just nodes! It could be expanded to all Content Entities fairly easily. This will likely be in its own properly named module with a better method for adding a UI to other content entities.

Requirements

This module requires no modules outside of Drupal core.

It currently supports cloning of most field types including Inline Entity Form and Field Collection.

Installation

Install the Quick Node Clone module as you would normally install a contributed Drupal module. Visit https://www.drupal.org/node/1897420 for further information.

Configuration

  • Navigate to Home >> Administration >> Configuration >> Quick Node Clone setting. Here you can customise text to prepend to title as per your needs

    Configure quick node clone

  • Clone publication status of original

    Publication status

    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
    You can exclude particular content type and it's field

    Exclusion settings

  • This module also supports 'paragraphs', allowing us to exclude any paragraph field from being cloned, similar to nodes
     

    Paragraph clone settings

  • Permissions
    This module provides a set of permissions. Go to admin/people/permissions/module/quick_node_clone and for any content type, we can grant permission to clone its nodes.
     

How to use

  1.  Go to available existing node and edit
  2. A Clone tab is now available on edit node.
  3. Select the Clone tab and a new node is created and the fields from the previous node are populated as per configuration.
  4.  Make appropriate edits and Save New 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:

use Drupal\node\NodeInterface;

/**
 * Implements hook_cloned_node_alter().
 */
function mymodule_cloned_node_alter(NodeInterface $cloned_node, NodeInterface $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:

use Drupal\paragraphs\Entity\Paragraph;

/**
 * Implements hook_cloned_node_paragraph_field_alter().
 */
function mymodule_cloned_node_paragraph_field_alter(Paragraph $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.

Maintainers

Help improve this page

Page status: No known problems

You can: