You are here

protected function TransactionForm::prepareEntity in Transaction 8

Prepares the entity object before the form is built first.

Overrides ContentEntityForm::prepareEntity

File

src/Form/TransactionForm.php, line 62

Class

TransactionForm
Form controller for the transaction entity.

Namespace

Drupal\transaction\Form

Code

protected function prepareEntity() {

  /** @var \Drupal\transaction\TransactionInterface $transaction */
  $transaction = $this->entity;

  // This entity form serves specific target entity routes as well, where the
  // target entity argument has the same name that the target entity type.
  if (!$transaction
    ->getTargetEntityId()) {
    $route_options = $this
      ->getRouteMatch()
      ->getRouteObject()
      ->getOptions();
    $target_entity_type_id = isset($route_options['_transaction_target_entity_type_id']) ? $route_options['_transaction_target_entity_type_id'] : $transaction
      ->getType()
      ->getTargetEntityTypeId();
    if ($target_entity = $this
      ->getRequest()
      ->get($target_entity_type_id)) {
      $transaction
        ->setTargetEntity($target_entity);
    }
  }
}