StepIndicator.php in Simple multi step form 8.x
File
src/StepIndicator.php
View source
<?php
namespace Drupal\simple_multistep;
use Drupal\Core\Form\FormStateInterface;
class StepIndicator extends FormStep {
public function __construct(array $form, FormStateInterface $form_state, $current_step) {
parent::__construct($form, $form_state);
$this->currentStep = $current_step;
}
private function createIndicator() {
$steps_label = array(
'#type' => 'item',
'#weight' => -1,
);
$markup = '<div class="multi-steps-label">';
foreach ($this->steps as $step_number => $step) {
$format_settings = $step->format_settings;
if ($format_settings['show_step_title']) {
$active = $this->currentStep == $step_number ? ' active' : '';
$markup .= '<div class="step-label' . $active . '">';
$markup .= $step->label;
$markup .= '</div>';
}
}
$markup .= '</div>';
$steps_label['#markup'] = $markup;
return $steps_label;
}
public function render(array &$form) {
$form['steps_label'] = $this
->createIndicator();
}
}