Problem/Motivation

In #3051503: Implement a confirmation form before the transition the option for confirmation forms was included and a question was phrased in comments 18-20. However I ran into issues when adding translations for this question.

The question Are you sure you want to %transition_label @entity_label? made (for me) sense in English as you will get questions like:

  • Are you sure you want to [place order] [1]?
  • Are you sure you want to [promote] [Bob]
  • Are you sure you want to [promote user] [Bob]
  • Are you sure you want to [publish content] [My cool node title]

But, because the transition label is a fixed string, this is proving difficult to translate.

"Are you sure you want to place order 1?" would translate in Dutch to "Weet u zeker dat u order 1 wilt plaatsen?". "Place order" translates to "order plaatsen", which works on a button, but in a sentence these words are no longer next to each other.

Proposal

I suppose the only way to overcome this, is to make the question have the transition in quotes. As jsacksick kind of suggested in #3051503-18: Implement a confirmation form before the transition bullet 5.

  • "Are you sure you want to apply transition '[promote user]' to [Bob]?"
  • "Are you sure you want to apply transition '[place order]' to [1]?" (Commerce might need a class override or label 'Order 1'.)
  • "Are you sure you want to apply transition '[publish content]' to [My cool node title]?"

Alternatively we could leave out the transition label entirely and use from and to states.

  • "Are you sure you want to transition [Bob] from [junior] to [senior]?"
  • "Are you sure you want to transition [1] from [draft] to [placed]?" (Commerce might need a class override or label 'Order 1'.)
  • "Are you sure you want to transition [My cool node title] from [draft] to [published]?"

There probably is never going to be a fit solution for every use case, but it would be nice of the standard question can be translated into something that makes sense. (Especially for a confirmation question.)

Wondering how this would also hold up for other languages.

Comments

Neograph734 created an issue. See original summary.

jsacksick’s picture

Since we're already in "context", and especially when combined with the modal (introduced in #3220573: Add option to display confirmation form in a modal to the formatter), I'm thinking omitting the entity label could be fine... (i.e Are you sure you want to "Place order"?).

Regarding your suggestions, we could also do:

"Are you sure you want to move [My cool node title] from [draft] to [published]?"

When recording state transitions for orders, commerce_log defines this template:
"Order moved from <em>{{ from_state }}</em> to <em>{{ to_state }}</em> by the <em>{{ transition_label }}</em> transition."

Additionally, there's one alternative option we haven't explored yet which is to update the description text, which currently simply says "This action cannot be undone".

The description could say something like the following instead:

Clicking on '%transition_label' will move the %entity_label from %from_state to %to_state. This action cannot be undone.

Though if we go this route, it'll also be complex to find a description text that fits for all entity types / transitions.

rszrama’s picture

Great feedback! I see a problem even in the use of the word "to" in the sentence, because in English, "to" is what signifies an infinitive (e.g. "to place"), while other languages just use a different case ... meaning "place" itself would be morphed to represent the infinitive, even though in the original context "place" is an imperative. Practically speaking, I think it will be impossible to have a "correct" sentence that's meaningfully translatable.

So ... I actually really like Jonathan's suggestion as an elegant workaround that trades out a "nice" full sentence for having a simple question ("Are you sure you want to apply this transition?") with technical details. It may not be as user-friendly to the merchant, but it'll be absolutely clear.

My proposal would essentially be:

Are you sure you want to apply this transition?

Transition: [transition label]
[Entity type]: [entity label]
From: [from state label]
To: [to state label]

(I'm just not sure if we need to bold the items on the left or not ... may be necessary for readability.)

neograph734’s picture

That makes sense and cannot go wrong, but perhaps ensure that the original "this cannot be undone" also remains?

jsacksick’s picture

Status: Active » Needs review
StatusFileSize
new5.78 KB
new27.22 KB
new27.08 KB

The attached patch implements the proposal from #3.

If we all come to an agreement, we can commit this, tag a new release so Commerce can require State machine 1.4 and benefit from the modals in the next version that's planned for tomorrow (2.25).

Tried 2 different versions:

Using a list:

Using a regular paragraph (option chosen):

Thoughts?

jsacksick’s picture

StatusFileSize
new5.78 KB

Fixed phpcs violations.

jsacksick’s picture

As a side note, it feels a bit weird to not get a confirmation message... But that's another issue that we can probably address later.

mglaman’s picture

Status: Needs review » Needs work
  1. +++ b/src/Form/StateTransitionConfirmForm.php
    @@ -24,6 +32,15 @@ class StateTransitionConfirmForm extends ContentEntityConfirmFormBase {
    +  /**
    +   * {@inheritdoc}
    +   */
    +  public static function create(ContainerInterface $container) {
    +    $instance = parent::create($container);
    +    $instance->renderer = $container->get('renderer');
    +    return $instance;
    +  }
    

    You can do this on a protected method? You need a setter method for the property.

  2. +++ b/src/Form/StateTransitionConfirmForm.php
    @@ -46,18 +63,36 @@ class StateTransitionConfirmForm extends ContentEntityConfirmFormBase {
    +    return $this->renderer->render($description);
    

    You should use `renderPlain` here to avoid leaked cache data.

jsacksick’s picture

Status: Needs work » Needs review
StatusFileSize
new5.79 KB

You can do this on a protected method? You need a setter method for the property.

Yes, and core does that in multiple places.

You should use `renderPlain` here to avoid leaked cache data.

Done!

mglaman’s picture

+1 looks good to me.

neograph734’s picture

Modal looks good and the text is super clear without the need for difficult translations. Great! I too think option 2 looks the best.

I am having some issues with submitting the form without the modal though, but I suppose that might have been caused by #3220573: Add option to display confirmation form in a modal to the formatter instead? (I have some more feedback on that issue that you might want to get in the release...)

neograph734’s picture

Status: Needs review » Reviewed & tested by the community

  • jsacksick committed 1a73b36 on 8.x-1.x
    Issue #3220535 by jsacksick, Neograph734, mglaman, rszrama: Improve the...
jsacksick’s picture

Status: Reviewed & tested by the community » Fixed

Committed! Thanks everyone!

Status: Fixed » Closed (fixed)

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