W3cubDocs

/Drupal 8

protected function ContentEntityForm::init

protected ContentEntityForm::init(FormStateInterface $form_state)

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

File

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

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);
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Entity!ContentEntityForm.php/function/ContentEntityForm::init/8.1.x