- π©π°Denmark ressa Copenhagen
I agree, this would be an awesome feature. I tried to make the examples work in the current release, and failed with both of them ... so an update and a working example would be fantastic :)
- π§π·Brazil joaopauloc.dev
Hello folks.
I created an issue to make it easy to extend the MultistepController for another reason. https://www.drupal.org/project/simple_multistep/issues/3501547 β¨ Make MultistepController easy overrided Active
but I also had to implement the navigation between the steps.
So, this is how I did.
Apply my patch in the issue above.
Extends the MultistepController creating your custom controller.
Inside this class override the addStepIndicator.
In my case I created another Step indicator extending from StepIndicator and this is the result./** * The ResourceStepIndicator class. * * @package Drupal\uwas_resource\SimpleMultistep */ class ResourceStepIndicator extends StepIndicator { /** * Render the step indicator. * * @param array $form * The form array. */ public function render(array &$form): void { $form['steps_label'] = $this->createStepsIndicator(); } /** * Create steps indicator. * * @return array * Returns the steps label. */ public function createStepsIndicator(): array { $data = [ '#type' => 'container', '#weight' => -100, ]; foreach ($this->getSteps() as $step_number => $step) { $format_settings = $step->format_settings; if ($format_settings['show_step_title']) { $button = [ '#type' => 'button', '#value' => $step->label, '#validate' => [self::class . '::moveStep'], '#step_number' => $step_number, ]; if ($this->currentStep === $step_number) { $button['#disabled'] = TRUE; $button['#attributes']['class'][] = 'active'; } $data[] = $button; } } return $data; } /** * Move step. * * @param array $form * Form array. * @param \Drupal\Core\Form\FormStateInterface $form_state * Form state object. */ public static function moveStep($form, FormStateInterface $form_state): void { $multiStep = $form_state->get('multistep_controller'); $triggering_element = $form_state->getTriggeringElement(); $step_number = $triggering_element['#step_number'] ?? -1; $entity_form = $form_state->getFormObject(); if ($entity_form instanceof EntityFormInterface) { $entity_updated = $entity_form->buildEntity($form, $form_state); $entity_form->setEntity($entity_updated); } $form_state->set('step', $step_number); $multiStep->updateCurrentStep($step_number); $form_state->set('multistep_controller', $multiStep); $form_state->setRebuild(); } }