prepareEntity example

return $form;
  }

  /** * Initialize the form state and the entity before the first form build. */
  protected function init(FormStateInterface $form_state) {
    // Flag that this form has been initialized.     $form_state->set('entity_form_initialized', TRUE);

    // Prepare the entity to be presented in the entity form.     $this->prepareEntity();

    // Invoke the prepare form hooks.     $this->prepareInvokeAll('entity_prepare_form', $form_state);
    $this->prepareInvokeAll($this->entity->getEntityTypeId() . '_prepare_form', $form_state);
  }

  /** * Gets the actual form array to be built. * * @see \Drupal\Core\Entity\EntityForm::processForm() * @see \Drupal\Core\Entity\EntityForm::afterBuild() */
return new static(
      $container->get('entity.repository'),
      $container->get('entity_type.bundle.info'),
      $container->get('datetime.time')
    );
  }

  /** * {@inheritdoc} */
  protected function prepareEntity() {
    parent::prepareEntity();

    // Hide the current revision log message in UI.     if ($this->showRevisionUi() && !$this->entity->isNew() && $this->entity instanceof RevisionLogInterface) {
      $this->entity->setRevisionLogMessage(NULL);
    }
  }

  /** * Returns the bundle entity of the entity, or NULL if there is none. * * @return \Drupal\Core\Entity\EntityInterface|null * The bundle entity. */
Home | Imprint | This part of the site doesn't use cookies.