View source
<?php
namespace Drupal\simple_multistep;
use Drupal\Core\Form\FormStateInterface;
class FormButton extends FormStep {
public function __construct(array $form, FormStateInterface $form_state, $current_step) {
parent::__construct($form, $form_state);
$this->currentStep = $current_step;
$this
->fetchStepSettings();
}
private function showBackButton(array &$form) {
$step_format_settings = $this->stepSettings->format_settings;
if ($this->currentStep != 0 && !empty($step_format_settings['back_button_show'])) {
$form['actions']['back_button'] = [
'#type' => 'button',
'#value' => $step_format_settings['back_button_text'],
'#validate' => [
'simple_multistep_register_back',
],
'#submit' => [],
'#limit_validation_errors' => [],
'#weight' => 0,
];
}
}
private function showNextButton(array &$form) {
$step_format_settings = $this->stepSettings->format_settings;
if (count($this->steps) - 1 != $this->currentStep) {
$form['actions']['next'] = [
'#type' => 'button',
'#value' => $step_format_settings['next_button_text'],
'#validate' => [
'simple_multistep_register_next_step',
],
'#submit' => [],
'#weight' => 0.1,
];
$form['actions']['submit']['#access'] = FALSE;
}
else {
$form['actions']['submit']['#access'] = TRUE;
array_unshift($form['#validate'], 'simple_multistep_multistep_validate');
}
}
public function render(array &$form) {
$this
->showBackButton($form);
$this
->showNextButton($form);
}
}