You are here

function ds_field_ui_layout_clone in Display Suite 8.3

Same name and namespace in other branches
  1. 8.4 includes/field_ui.inc \ds_field_ui_layout_clone()
  2. 8.2 includes/field_ui.inc \ds_field_ui_layout_clone()
  3. 7.2 includes/ds.field_ui.inc \ds_field_ui_layout_clone()
  4. 7 ds.field_ui.inc \ds_field_ui_layout_clone()

Clone a fields layout.

1 string reference to 'ds_field_ui_layout_clone'
_ds_field_ui_table_layouts in includes/field_ui.inc
Add the layouts fieldset on the Field UI screen.

File

includes/field_ui.inc, line 624
Field UI functions for Display Suite.

Code

function ds_field_ui_layout_clone($form, FormStateInterface $form_state) {
  $clone = $form_state
    ->getValue('clone');
  list(, , $cv) = explode('.', $clone);
  $entity_type = $form['#entity_type'];
  $bundle = $form['#bundle'];

  /* @var \Drupal\Core\Entity\EntityFormInterface $entity_form */
  $entity_form = $form_state
    ->getFormObject();

  // Get the entity display.

  /* @var \Drupal\Core\Entity\Display\EntityDisplayInterface $old_display */
  $old_display = $entity_form
    ->getEntity();
  $view_mode = $old_display
    ->getMode();
  $old_display
    ->delete();

  /* @var \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display */
  $display = EntityViewDisplay::load($entity_type . '.' . $bundle . '.' . $cv);
  $clone_display = $display
    ->createCopy($view_mode);
  $clone_display
    ->save();

  // Show message.
  \Drupal::messenger()
    ->addMessage(t('The layout has been cloned.'));
}