Add method to retrieve the transition in "StateTransitionConfirmForm"

Created on 31 March 2023, over 1 year ago
Updated 16 May 2023, over 1 year ago

Problem/Motivation

Trying to alter the StateTransitionConfirmForm, we were unable to retrieve the transition. It was a key part to determine that alterations to make in the form.

It is a protected property passed to the form constructor, so we were unable to find the way to get it from the hook_form_alter() context.

Proposed resolution

Add a getTransition() method to this form class that allows to access to the $transition object.

Feature request
Status

Fixed

Version

1.0

Component

Code

Created by

🇪🇸Spain plopesc Valladolid

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @plopesc
  • @plopesc opened merge request.
  • 🇪🇸Spain plopesc Valladolid
  • Status changed to Needs review over 1 year ago
  • 🇳🇱Netherlands neograph734 Netherlands

    The field name and transition id are passed to the form builder, so you can recover the transition. I have always used below approach:

      $build_info = $form_state->getBuildInfo();
      [$field_name, $transition_id] = $build_info['args'];
    
      $state_item = $build_info['callback_object']->getEntity()->get($field_name)->first();
      /** @var \Drupal\state_machine\Plugin\Workflow\WorkflowTransition $transition */
      $transition = $state_item->getWorkflow()->getTransition($transition_id);
    

    But I must say that your method looks much better. It can then be accessed via $form_state->getFormObject()->getTransition()?

  • Status changed to RTBC over 1 year ago
  • 🇳🇱Netherlands neograph734 Netherlands

    Confirming this works and it is a much better method than what I used.

  • Status changed to Fixed over 1 year ago
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024