You are here

function field_group_field_ui_clone_field_groups_validate in Field Group 8

Same name and namespace in other branches
  1. 8.3 includes/field_ui.inc \field_group_field_ui_clone_field_groups_validate()
  2. 7 field_group.field_ui.inc \field_group_field_ui_clone_field_groups_validate()

Validate handler to validate saving existing fieldgroups from one view mode or form to another.

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

File

includes/field_ui.inc, line 520
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_validate($form, FormStateInterface $form_state) {
  $form_state_values = $form_state
    ->getValues();
  $field_group_params = $form_state
    ->get('field_group_params');
  list($context, $mode) = explode('.', $form_state_values['fieldgroup_clone']);
  $source_groups = field_group_info_groups($field_group_params->entity_type, $field_group_params->bundle, $context, $mode);

  // Check for types are not known in current mode.
  if ($field_group_params->context != 'form') {
    $non_existing_types = [];
  }
  else {
    $non_existing_types = [
      'html_element',
    ];
  }
  foreach ($source_groups as $key => $group) {
    if (in_array($group->format_type, $non_existing_types)) {
      unset($source_groups[$key]);
      drupal_set_message(t('Skipping @group because this type does not exist in current mode', array(
        '@group' => $group->label,
      )), 'warning');
    }
  }
  if (empty($source_groups)) {

    // Report error found with selection.
    $form_state
      ->setErrorByName('additional_settings][fieldgroup_clone', t('No field groups were found in selected view mode.'));
    return;
  }
  $form_state
    ->set('#source_groups', $source_groups);
}