This module adds a "Copy block" button to Drupal's Layout Builder interface. This allows users to duplicate any inline block within a section, creating a completely independent copy that can be edited or deleted without affecting the original.
Layout Builder Block Copy adds a Copy block link to the contextual links of every block in Drupal's Layout Builder. The copy is placed directly after the original, in the same section and region, with the same settings and position.
Inline blocks are deep-copied: each copy gets its own block_content entity, so editing or deleting one never changes the other. Paragraphs and other composite entities referenced through Entity Reference Revisions are duplicated too, at any nesting depth. Plain references, such as media items or taxonomy terms, still point at the same item. Reusable content blocks are copied as another placement of the same block, with a warning that both placements share their content.
Features
- One-click copy from a block's contextual links, for content layouts (overrides) and default layouts.
- Copies work like any other Layout Builder change: nothing is saved until you save the layout, and discarding your changes leaves nothing behind.
- Copies own their own paragraphs, including copies of copies that have not been saved yet.
- Access control:
- Copying uses the same access as editing the layout.
- Copying an inline block also requires "Create and edit custom blocks", the permission core requires to add one.
- Access is checked against the unsaved layout.
- Links are protected by CSRF tokens.
- Layout Builder Lock support: blocks cannot be copied into sections locked against adding blocks, or into locked regions, unless the user has the lock module's bypass permission.
- Broken blocks are refused, with a clear message: inline blocks whose content is missing, and placements of blocks that were deleted or are no longer reusable.
- Inline block usage is tracked correctly, including copies placed in entities that are not saved yet, so Drupal cleans up blocks as it does for blocks added normally.
- A Drush command repairs and reports inline block usage left behind by older releases:
drush layout-builder-block-copy:repair-usage --dry-run -v(2.0.x),drush layout_builder_block_copy:repair-usage --dry-run(1.1.x). It never deletes blocks. - For developers:
BlockCopyManagerInterface::deepCloneComponent()copies a component in code, for example when cloning whole entities.hook_layout_builder_block_copy_access()lets other modules forbid copies, for example to enforce block limits per region.
- No contributed dependencies; only Drupal core's Layout Builder and Block Content.
Which version should I use?
2.0.x (recommended) 1.1.x Drupal 11.2 or later, and 12 10.3 or later, and 11 PHP 8.3 or later 8.1 or later (8.3 recommended) Code style Object-oriented hooks (#[Hook]), autowired services
Procedural hooks, for Drupal 10 compatibility
Status
Actively developed; new features land here
Maintained for Drupal 10 sites; bug and security fixes
Both branches copy blocks in the same way and have the same permissions, Layout Builder Lock support and API. Code written for 1.1.x works on 2.0.x, except cleanupOrphanedComponent(). It is deprecated in 1.1.x and removed in 2.0.x, because copies are no longer saved before the layout is. The Drush repair commands differ slightly: in 2.0.x it can also re-assign default-layout blocks to their display (--reown-defaults) and list the blocks that need review (-v).
The 1.0.x branch is no longer supported. Update to 1.1.x or 2.0.x and run drush updatedb: releases before 1.0.9 saved copies without recording their usage, and the update repairs this.
Requirements
- Core Layout Builder and Block Content modules.
- Drupal and PHP versions as in the table above.
Compared to Layout Builder Block Clone
This module was created to address known issues in the similar Layout Builder Block Clone project, including shallow cloning and Drupal 11 incompatibility.
Ask your assistant about Layout Builder Block Copy
Check compatibility with your Drupal and PHP version, maintenance and security coverage, from current release data. How it works
Depends on
Dependencies of the latest stable release
- block_content Drupal core
- layout_builder Drupal core
Required by
Tracked projects that depend on this one
No tracked projects depend on this one yet.