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'] = array(
'#type' => 'button',
'#value' => $step_format_settings['back_button_text'],
'#validate' => array(
'simple_multistep_register_back',
),
'#submit' => array(),
'#limit_validation_errors' => array(),
);
}
}
private function showNextButton(array &$form) {
$step_format_settings = $this->stepSettings->format_settings;
if (count($this->steps) - 1 != $this->currentStep) {
$form['actions']['next'] = array(
'#type' => 'button',
'#value' => $step_format_settings['next_button_text'],
'#validate' => array(
'simple_multistep_register_next_step',
),
'#submit' => array(),
);
$form['actions']['submit']['#access'] = FALSE;
}
else {
$form['actions']['submit']['#access'] = TRUE;
$form['#validate'][] = 'simple_multistep_multistep_validate';
}
}
public function render(array &$form) {
$this
->showNextButton($form);
$this
->showBackButton($form);
}
}