You are here

function ds_field_ui_fields_layouts in Display Suite 8.3

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

Adds the Display Suite fields and layouts to the form.

1 call to ds_field_ui_fields_layouts()
ds_form_entity_view_display_edit_form_alter in ./ds.module
Implements hook_form_alter().

File

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

Code

function ds_field_ui_fields_layouts(&$form, FormStateInterface $form_state) {
  global $base_root, $base_path;

  // Get the entity_type, bundle and view mode.
  $entity_type = $form['#entity_type'];
  $bundle = $form['#bundle'];

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

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

  // Check layout builder.
  if ($entity_display instanceof LayoutBuilderEnabledInterface && $entity_display
    ->isLayoutBuilderEnabled()) {
    return;
  }

  // Create vertical tabs.
  ds_field_ui_create_vertical_tabs($form);

  // Add layout fieldset.
  _ds_field_ui_table_layouts($entity_type, $bundle, $view_mode, $form, $form_state);

  // Add/alter fields on the table, but only if a layout is selected.
  if (!empty($form['#ds_layout'])) {
    _ds_field_ui_fields($entity_type, $bundle, $view_mode, $form, $form_state);

    // Also alter core fields.
    _ds_field_ui_core_fields($form, $form_state);
  }

  // Special validate function for field group.
  if ($form_state
    ->has('no_field_group')) {
    array_unshift($form['#validate'], '_ds_field_group_field_ui_fix_notices');
  }

  // Attach js.
  $form['#attached']['library'][] = 'ds/admin';

  // Add process function to add the regions.
  $form['#process'][] = 'ds_field_ui_regions';

  // Add a destination so we can get back if layout has been changed.
  $form['ds_source'] = [
    '#type' => 'hidden',
    '#value' => $base_root . $base_path,
  ];
  $form['ds_destination'] = [
    '#type' => 'hidden',
    '#value' => \Drupal::destination()
      ->getAsArray(),
  ];
  $form['ds_entity_type'] = [
    '#type' => 'hidden',
    '#value' => $entity_type,
  ];
  $form['ds_bundle'] = [
    '#type' => 'hidden',
    '#value' => $bundle,
  ];
  $form['ds_view_mode'] = [
    '#type' => 'hidden',
    '#value' => $view_mode,
  ];
}