Layout Replicate
================

Clones Drupal Layout Builder layouts between nodes and/or languages. Supports
cloning an entire layout, a single section, or a single block. Inline block
content entities are deep-cloned so each target gets fully independent copies.

Compatible with Drupal 10 and 11.


REQUIREMENTS
------------
 - Drupal core Layout Builder enabled on the target content type (allow overrides)
 - node and block_content core modules
 - language and content_translation only needed for multi-language workflows


INSTALLATION
------------
1. Place the layout_replicate/ folder inside web/modules/custom/
2. Enable and clear caches:

   drush en layout_replicate -y
   drush cr


PERMISSIONS
-----------
 - administer nodes       Required to see and use the Clone Layout tab
 - bypass node access     Required to edit the target node (Drupal 11)
 - configure any layout   Required to open the Layout Builder editor after cloning


USAGE
-----
A "Clone Layout" tab appears on every Layout Builder-enabled node for users
with the "administer nodes" permission. It does not appear on nodes whose
content type has not enabled Layout Builder overrides.

Unified form: /node/{nid}/clone-layout

The form handles three clone operations selected via radio buttons:

  Entire layout
    Replaces all sections and blocks on the target with a copy of the source.
    The target's existing layout is permanently overwritten.

  A section
    Appends one section (with all its blocks) to the end of the target layout.

  A block
    Appends one block into a new section at the end of the target layout.

Form fields:

  What to clone        : Entire layout, A section, or A block
  From - Language      : Language of this node to read from
  From - Section       : (section/block ops) Which section to clone from
  From - Block         : (block op) Which block within that section
  To - Destination node: Autocomplete. Leave blank to clone within same node
  To - Language        : Language to write into on the target node
  Deep-clone inline blocks
                       : Recommended. Creates independent block_content
                         entities so editing one does not affect the other.

After a successful clone the form redirects to the Layout Builder editor on
the target node.


DEEP-CLONE BEHAVIOUR
--------------------
  Inline blocks (inline_block:*)
    ON  - New independent block_content entity created. block_id and
          block_revision_id point to the new entity.
    OFF - Original entity shared between source and target.

  Reusable blocks, field blocks, views, etc.
    Shared reference is always preserved (correct Drupal behaviour).

Block order within each section is preserved.


ACTIVITY LOG
------------
Every clone operation is recorded and viewable at:

   /admin/reports/layout-replicate

Each entry shows the operation type (layout/section/block), source and target
node IDs, languages, and timestamp.


PHP API
-------
  $service = \Drupal::service('layout_replicate.service');

  // Clone entire layout.
  $service->replicateLayout($sourceNode, 'en', $targetNode, 'ar');

  // Clone one section (zero-based delta).
  $service->replicateSection($sourceNode, 'en', 2, $targetNode, 'en');

  // Clone one block into a new section on the target.
  $service->replicateBlock($sourceNode, 'en', $uuid, $targetNode, 'en', 0);

All three methods accept an optional $deep_clone boolean (default TRUE).


ROUTES
------
  /node/{node}/clone-layout         Unified clone form (current)
  /node/{node}/replicate-layout     Legacy layout-only form
  /node/{node}/replicate-block      Legacy block form
  /node/{node}/replicate-section    Legacy section form
  /admin/reports/layout-replicate   Activity log


MAINTAINER
----------
Mahdi Al-Wadi
