public function TransactionOperationForm::buildEntity in Transaction 8
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()
File
- src/
Form/ TransactionOperationForm.php, line 114
Class
- TransactionOperationForm
- Builds the form to add or edit a transaction operation.
Namespace
Drupal\transaction\FormCode
public function buildEntity(array $form, FormStateInterface $form_state) {
/** @var \Drupal\transaction\TransactionOperationInterface $entity */
$entity = parent::buildEntity($form, $form_state);
// On new operations, set the transaction type in form values from request.
if ($entity
->isNew()) {
$transaction_type = $this
->getRequest()
->get('transaction_type');
$form_state
->setValue('transaction_type', is_string($transaction_type) ? $transaction_type : $transaction_type
->id());
}
// Process the details textarea.
$details = !empty($submitted_details = $form_state
->getValue('details')) ? explode("\n", $submitted_details) : [];
$entity
->setDetails($details);
return $entity;
}