function FieldStorageConfigEditForm::form

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

Overrides EntityForm::form

File

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

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['#title'] = $field_label;
    $form['#prefix'] = '<p>' . $this->t('These settings apply to the %field field everywhere it is used. These settings impact the way that data is stored in the database and cannot be changed once data has been created.', [
        '%field' => $field_label,
    ]) . '</p>';
    // See if data already exists for this field.
    // If so, prevent changes to the field settings.
    if ($this->entity
        ->hasData()) {
        $form['#prefix'] = '<div class="messages messages--error">' . $this->t('There is data for this field in the database. The field settings can no longer be changed.') . '</div>' . $form['#prefix'];
    }
    // 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);
    $items = $entity->get($this->entity
        ->getName());
    $item = $items->first() ?: $items->appendItem();
    $form['settings'] += $item->storageSettingsForm($form, $form_state, $this->entity
        ->hasData());
    // Add the cardinality sub-form.
    $form['cardinality_container'] = $this->getCardinalityForm();
    return $form;
}

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