diff --git a/src/Form/ShareTransactionValidateForm.php b/src/Form/ShareTransactionValidateForm.php index 1e2798d76660294f9ef6ae9a3a340b4fe92b9b7c..0266d456a571dbf0ec618899622b8402de2a5c1a 100644 --- a/src/Form/ShareTransactionValidateForm.php +++ b/src/Form/ShareTransactionValidateForm.php @@ -27,7 +27,7 @@ class ShareTransactionValidateForm extends FormBase { public function buildForm(array $form, FormStateInterface $form_state) { $current_url = Url::fromRoute('<current>')->toString(); $params = Url::fromUserInput($current_url)->getRouteParameters(); - $form_state->getStorage()['transaction'] = $params['share_transaction']; + $form_state->set('transaction', $params['share_transaction']); $form['date'] = [ '#type' => 'date', @@ -36,14 +36,50 @@ class ShareTransactionValidateForm extends FormBase { '#required' => TRUE, '#default_value' => date('Y-m-d'), ]; + + $form['needs_confirmation'] = [ + '#type' => 'hidden', + '#title' => $this->t('Date needs confirmation'), + '#default_value' => FALSE, + ]; + + $form['date_confirmed'] = [ + '#type' => 'checkbox', + '#title' => $this->t('Are you sure you wish to proceed with this date?'), + '#access' => $form_state->get('needs_confirmation') ? TRUE : FALSE, + ]; + $form['submit'] = [ '#type' => 'submit', '#value' => $this->t('Submit'), + '#limit_validation_errors' => [], ]; return $form; } + /** + * {@inheritdoc} + */ + public function validateForm(array &$form, FormStateInterface $form_state) { + parent::validateForm($form, $form_state); + $transaction = ShareTransaction::load($form_state->getStorage()['transaction']); + + if (($date = $form_state->getValue('date')) && + !$form_state->getValue('date_confirmed')) { + + if ($date > date('Y-m-d')) { + $form_state->set('needs_confirmation', TRUE); + $form_state->setRebuild(TRUE); + } + elseif (($payment_date = $transaction->getPaymentDate()) && + $date != $payment_date) { + $form_state->set('needs_confirmation', TRUE); + $form_state->setRebuild(TRUE); + } + } + } + /** * {@inheritdoc} */