Please make action buttons more unique.

Use case 1 (OP):
When two or more state transition buttons have the same label, all buttons with the same label will cause a transition to the state of the last button to be created.

For example, lets say there are three states available: A, B, and C. Some node is in the "A" state and displays two workflow transition buttons with the same label "D". Inspecting the button HTML shows that each button has a different ID: "edit-workflow-2" (B) and "edit-workflow-3" (C), but both have the label "D". Clicking on the button with the ID "edit-workflow-2" should move the node to state B, but it actually moves the node to state C. Clicking on the button with the ID "edit-workflow-3" correctly moves the node to state C as expected.

I understand that it may not be a common occurrence to have multiple buttons with the same label, but I think this should still be fixed. Either prevent multiple button labels in the same state from having the same name, or correct the code to not rely on button labels to know which state to move to.

Use case 2(#2):
it would be helpful if the buttons had a unique identifier other than the label for the purpose of finding them on the workflow form (e.g., in a form_alter). Currently the buttons are keyed by the state they transition to, so finding them in the form means my code needs to hard-code transition sequence logic. The alternative is finding them using the label, which is worse.

Comments

honzifox created an issue. See original summary.

rubymuse’s picture

I second that for another reason: it would be helpful if the buttons had a unique identifier other than the label for the purpose of finding them on the workflow form (e.g., in a form_alter). Currently the buttons are keyed by the state they transition to, so finding them in the form means my code needs to hard-code transition sequence logic. The alternative is finding them using the label, which is worse.

johnv’s picture

Suggestions, patches with better naming are welcome.

rubymuse’s picture

The button element 'name' attribute appears to be the default value, 'op', for every button. If instead it was unique per button, it would solve my issue (which is not a bug per se) by allowing my code to locate the button uniquely without resorting to the label.

As for the original bug report, presumably the Workflow module code is doing what I'm trying to avoid doing -- using the button label to identify the button. The same unique names could be used instead. I'm sorry to say that a patch is beyond me at this time.

johnv’s picture

Component: Code » User interface

Regrouping issues for action buttons.

johnv’s picture

Title: Incorrect state transition when using multiple buttons with the same Label » Make action buttons more unique
Issue summary: View changes

  • johnv committed e711183 on 7.x-2.x
    Issue #2545660: Make action buttons more unique
    

  • johnv committed f2cbead on 8.x-1.x
    Issue #2545660: Make action buttons more unique
    
johnv’s picture

Status: Active » Fixed

Please reopen if this is not sufficient.

Above commit adds:

$workflow_submit_button['#attributes']['class'][] = drupal_html_class('workflow_button_' . $option_name);

See also #2366867: Allow CSS/HTML in state / transition labels for other requirements.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.