function FieldStorageConfigEditForm::form

Same name and namespace in other branches
  1. 9 core/modules/field_ui/src/Form/FieldStorageConfigEditForm.php \Drupal\field_ui\Form\FieldStorageConfigEditForm::form()
  2. 8.9.x core/modules/field_ui/src/Form/FieldStorageConfigEditForm.php \Drupal\field_ui\Form\FieldStorageConfigEditForm::form()
  3. 10 core/modules/field_ui/src/Form/FieldStorageConfigEditForm.php \Drupal\field_ui\Form\FieldStorageConfigEditForm::form()

Gets the actual form array to be built.

Overrides EntityForm::form

File

core/modules/field_ui/src/Form/FieldStorageConfigEditForm.php, line 90

Class

FieldStorageConfigEditForm
Provides a form for the "field storage" edit page.

Namespace

Drupal\field_ui\Form

Code

public function form(array $form, FormStateInterface $form_state) {
  $form = parent::form($form, $form_state);
  $field_label = $form_state->get('field_config')
    ->label();
  $form['#prefix'] = '<p>' . $this->t('These settings apply to the %field field everywhere it is used. Some also impact the way that data is stored and cannot be changed once data has been created.', [
    '%field' => $field_label,
  ]) . '</p>';
  // Add the cardinality sub-form.
  $form['cardinality_container'] = $this->getCardinalityForm();
  // Add settings provided by the field module. The field module is
  // responsible for not returning settings that cannot be changed if
  // the field already has data.
  $form['settings'] = [
    '#weight' => -10,
    '#tree' => TRUE,
  ];
  // Create an arbitrary entity object, so that we can have an instantiated
  // FieldItem.
  $ids = (object) [
    'entity_type' => $form_state->get('entity_type_id'),
    'bundle' => $form_state->get('bundle'),
    'entity_id' => NULL,
  ];
  $entity = _field_create_entity_from_ids($ids);
  if (!$this->entity
    ->isNew()) {
    $items = $entity->get($this->entity
      ->getName());
  }
  else {
    $field_config = $form_state->get('field_config');
    $items = $this->typedDataManager
      ->create($field_config, name: $this->entity
      ->getName(), parent: EntityAdapter::createFromEntity($entity));
  }
  $item = $items->first() ?: $items->appendItem();
  $form['settings'] += $item->storageSettingsForm($form, $form_state, $this->entity
    ->hasData());
  return $form;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.