Change record status: 
Project: 
Introduced in branch: 
10.4.x, 11.1.x
Introduced in version: 
10.4.0, 11.1.0
Description: 

#3481238: Add a config action to clone a config entity added a very simple new config action that can be used to create a clone of any config entity, with a new ID.

You can use it like this:

config:
  actions:
    image.style.thumbnail_16x9:
      cloneAs: thumbnail_widescreen

That's it. The name of the action is cloneAs, and its only argument is the ID of the clone (without the config entity's prefix, which in this example is image.style).

If the cloned entity already exists (identified by its ID), it will be left untouched by default. But you can configure the action to fail with an error if the clone already exists:

config:
  actions:
    image.style.thumbnail_16x9:
      cloneAs:
        id: thumbnail_widescreen
        fail_if_exists: true

If you are cloning entities using wildcards, you can generate the clone IDs dynamically by using placeholders. In the following example, imagine there are two node types called alpha and beta, and both have a teaser display. You can clone these view modes like so:

config:
  actions:
    core.entity_view_display.node.*.teaser:
      # This will create two entity view displays: `node.alpha.search_index` and `node.beta.search_index`. The % is replaced with the part of the original entity's ID in the same position.
      cloneAs: node.%.search_index

This works for any entity with a compound ID (i.e., an ID made up of multiple period-separated parts), like entity displays and fields. Another example:

config:
  actions:
    # If there are already fields called `media.audio.field_description` and `node.page.field_description`, this will clone them as `media.audio.field_summary` and `node.page.field_summary`.
    field.field.*.*.field_description:
      cloneAs: %.%.field_summary
Impacts: 
Module developers
Site templates, recipes and distribution developers