You are here

function field_group_field_ui_clone_field_groups in Field Group 8.3

Same name and namespace in other branches
  1. 8 includes/field_ui.inc \field_group_field_ui_clone_field_groups()
  2. 7.2 field_group.field_ui.inc \field_group_field_ui_clone_field_groups()
  3. 7 field_group.field_ui.inc \field_group_field_ui_clone_field_groups()

Submit handler to save existing fieldgroups from one view mode or form to another.

1 string reference to 'field_group_field_ui_clone_field_groups'
field_group_field_ui_create_vertical_tabs in includes/field_ui.inc
Create vertical tabs.

File

includes/field_ui.inc, line 637
Field_group.field_ui.inc is a file that contains most functions needed on the Fields UI Manage forms (display and fields).

Code

function field_group_field_ui_clone_field_groups($form, FormStateInterface $form_state) {
  $fields = array_keys($form_state
    ->getValue('fields'));
  $source_groups = $form_state
    ->get('#source_groups');
  if ($source_groups) {
    $field_group_params = $form_state
      ->get('field_group_params');
    foreach ($source_groups as $source_group) {
      if (in_array($source_group->group_name, $fields)) {
        \Drupal::messenger()
          ->addMessage(t('Fieldgroup @group is not cloned since a group already exists with the same name.', [
          '@group' => $source_group->group_name,
        ]), 'warning');
        continue;
      }
      $source_group->context = $field_group_params->context;
      $source_group->mode = $field_group_params->mode;
      $source_group->children = [];
      field_group_group_save($source_group);
      \Drupal::messenger()
        ->addMessage(t('Fieldgroup @group cloned successfully.', [
        '@group' => $source_group->group_name,
      ]));
    }
  }
}