Skip to content
Snippets Groups Projects

Draft: fix: use EntityWorkflowStateForm for bank transaction state form

Closed simon requested to merge fix-bank-transaction-change-state-form into master
Compare and
1 file
+ 5
44
Preferences
File browser
Compare changes
@@ -2,17 +2,17 @@
namespace Drupal\banking\Form;
use Drupal\Core\Form\FormBase;
// use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Drupal\simple_workflows\Form\EntityWorkflowStateForm;
use Drupal\banking\Entity\BankTransaction;
/**
* Class BankTransactionStateForm.
*/
class BankTransactionStateForm extends FormBase {
class BankTransactionStateForm extends EntityWorkflowStateForm {
/**
* {@inheritdoc}
@@ -21,50 +21,11 @@ class BankTransactionStateForm extends FormBase {
return 'bank_transaction_state_form';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
protected function getEntity() {
$current_url = Url::fromRoute('<current>')->toString();
$params = Url::fromUserInput($current_url)->getRouteParameters();
$transaction = BankTransaction::load($params['bank_transaction']);
$form_state->getStorage()['transaction'] = $params['bank_transaction'];
$form['state'] = [
'#type' => 'select',
'#title' => $this->t('State'),
'#description' => $this->t('State of the transaction.'),
'#options' => [
'draft' => $this->t('draft'),
'manual' => $this->t('manual'),
'done' => $this->t('done'),
],
'#default_value' => $transaction->getState(),
'#weight' => '0',
];
$form['submit'] = [
'#type' => 'submit',
'#value' => $this->t('Submit'),
];
return $form;
}
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
parent::validateForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$transaction = BankTransaction::load($form_state->getStorage()['transaction']);
$transaction->setState($form_state->getValue('state'));
$transaction->save();
$form_state->setRedirect('entity.bank_transaction.canonical', ['bank_transaction' => $transaction->id()]);
return $transaction;
}
}