function EntityDisplayModeAddForm::buildForm

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

Overrides EntityForm::buildForm

File

core/modules/field_ui/src/Form/EntityDisplayModeAddForm.php, line 25

Class

EntityDisplayModeAddForm
Provides the add form for entity display modes.

Namespace

Drupal\field_ui\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, $entity_type_id = NULL) {
    $this->targetEntityTypeId = $entity_type_id;
    $form = parent::buildForm($form, $form_state);
    // Change replace_pattern to avoid undesired dots.
    $form['id']['#machine_name']['replace_pattern'] = '[^a-z0-9_]+';
    $definition = $this->entityTypeManager
        ->getDefinition($this->targetEntityTypeId);
    $form['#title'] = $this->t('Add new @entity-type %label', [
        '@entity-type' => $definition->getLabel(),
        '%label' => $this->entityType
            ->getSingularLabel(),
    ]);
    return $form;
}

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