function ContentEntityForm::init

Same name in other branches
  1. 9 core/lib/Drupal/Core/Entity/ContentEntityForm.php \Drupal\Core\Entity\ContentEntityForm::init()
  2. 8.9.x core/lib/Drupal/Core/Entity/ContentEntityForm.php \Drupal\Core\Entity\ContentEntityForm::init()
  3. 10 core/lib/Drupal/Core/Entity/ContentEntityForm.php \Drupal\Core\Entity\ContentEntityForm::init()

Initializes the form state and the entity before the first form build.

Parameters

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Overrides EntityForm::init

1 call to ContentEntityForm::init()
OverridesEntityForm::init in core/modules/layout_builder/src/Form/OverridesEntityForm.php
1 method overrides ContentEntityForm::init()
OverridesEntityForm::init in core/modules/layout_builder/src/Form/OverridesEntityForm.php

File

core/lib/Drupal/Core/Entity/ContentEntityForm.php, line 277

Class

ContentEntityForm
Entity form variant for content entity types.

Namespace

Drupal\Core\Entity

Code

protected function init(FormStateInterface $form_state) {
    // Ensure we act on the translation object corresponding to the current form
    // language.
    $this->initFormLangcodes($form_state);
    $langcode = $this->getFormLangcode($form_state);
    $this->entity = $this->entity
        ->hasTranslation($langcode) ? $this->entity
        ->getTranslation($langcode) : $this->entity
        ->addTranslation($langcode);
    $form_display = EntityFormDisplay::collectRenderDisplay($this->entity, $this->getOperation());
    $this->setFormDisplay($form_display, $form_state);
    parent::init($form_state);
}

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