public function ContentEntityForm::buildEntity in Drupal 10
Same name and namespace in other branches
- 8 core/lib/Drupal/Core/Entity/ContentEntityForm.php \Drupal\Core\Entity\ContentEntityForm::buildEntity()
- 9 core/lib/Drupal/Core/Entity/ContentEntityForm.php \Drupal\Core\Entity\ContentEntityForm::buildEntity()
Builds an updated entity object based upon the submitted form values.
For building the updated entity object the form's entity is cloned and the submitted form values are copied to entity properties. The form's entity remains unchanged.
Parameters
array $form: A nested array form elements comprising the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
\Drupal\Core\Entity\EntityInterface An updated copy of the form's entity object.
Overrides EntityForm::buildEntity
See also
\Drupal\Core\Entity\EntityFormInterface::getEntity()
1 call to ContentEntityForm::buildEntity()
- ContentEntityForm::validateForm in core/
lib/ Drupal/ Core/ Entity/ ContentEntityForm.php - Button-level validation handlers are highly discouraged for entity forms, as they will prevent entity validation from running. If the entity is going to be saved during the form submission, this method should be manually invoked from the button-level…
4 methods override ContentEntityForm::buildEntity()
- AccountForm::buildEntity in core/
modules/ user/ src/ AccountForm.php - Builds an updated entity object based upon the submitted form values.
- CommentForm::buildEntity in core/
modules/ comment/ src/ CommentForm.php - Builds an updated entity object based upon the submitted form values.
- MenuLinkContentForm::buildEntity in core/
modules/ menu_link_content/ src/ Form/ MenuLinkContentForm.php - Builds an updated entity object based upon the submitted form values.
- TermForm::buildEntity in core/
modules/ taxonomy/ src/ TermForm.php - Builds an updated entity object based upon the submitted form values.
File
- core/
lib/ Drupal/ Core/ Entity/ ContentEntityForm.php, line 153
Class
- ContentEntityForm
- Entity form variant for content entity types.
Namespace
Drupal\Core\EntityCode
public function buildEntity(array $form, FormStateInterface $form_state) {
/** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
$entity = parent::buildEntity($form, $form_state);
// Mark the entity as requiring validation.
$entity
->setValidationRequired(!$form_state
->getTemporaryValue('entity_validated'));
// Save as a new revision if requested to do so.
if ($this
->showRevisionUi() && !$form_state
->isValueEmpty('revision')) {
$entity
->setNewRevision();
if ($entity instanceof RevisionLogInterface) {
// If a new revision is created, save the current user as
// revision author.
$entity
->setRevisionUserId($this
->currentUser()
->id());
$entity
->setRevisionCreationTime($this->time
->getRequestTime());
}
}
return $entity;
}