You are here

class StepIndicator in Simple multi step form 8.x

Same name and namespace in other branches
  1. 8 src/StepIndicator.php \Drupal\simple_multistep\StepIndicator

Class StepIndicator.

@package Drupal\simple_multistep

Hierarchy

Expanded class hierarchy of StepIndicator

File

src/StepIndicator.php, line 12

Namespace

Drupal\simple_multistep
View source
class StepIndicator extends FormStep {

  /**
   * Constructor.
   *
   * @param array $form
   *   Form settings.
   * @param \Drupal\Core\Form\FormStateInterface $form_state
   *   Form state object.
   * @param int $current_step
   *   Current step.
   */
  public function __construct(array $form, FormStateInterface $form_state, $current_step) {
    parent::__construct($form, $form_state);
    $this->currentStep = $current_step;
  }

  /**
   * Create indicator.
   */
  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;
  }

  /**
   * Get Indicator.
   *
   * @param array $form
   *   Reference to form.
   */
  public function render(array &$form) {
    $form['steps_label'] = $this
      ->createIndicator();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FormStep::$currentStep protected property Current step.
FormStep::$form protected property Form array.
FormStep::$formState protected property Form state.
FormStep::$steps protected property Steps.
FormStep::$stepSettings protected property Step settings.
FormStep::fetchSteps protected function Get array with form steps.
FormStep::fetchStepSettings protected function Fetch form step settings by current step.
FormStep::getAllChildren protected function Get all child from field group.
FormStep::getCurrentStep public function Get current step.
FormStep::getSteps public function Get all form steps.
FormStep::getStepSettings public function Get form step settings.
FormStep::getStepValues public function Get submission values for current step.
FormStep::increaseStep public function Increase step number.
FormStep::reduceStep public function Reduce step number.
FormStep::setCurrentStep protected function Set current step.
FormStep::setFormState public function Set $form_state.
FormStep::sortStep protected static function Sort array by object property.
FormStep::updateStepInfo public function Update step info.
StepIndicator::createIndicator private function Create indicator.
StepIndicator::render public function Get Indicator.
StepIndicator::__construct public function Constructor. Overrides FormStep::__construct