'string_to_add' form element never increments

Created on 8 June 2018, over 6 years ago
Updated 28 July 2024, 4 months ago

In QueueExampleForm.php, line #92, $form_state->get('insert_counter'), always return an empty value.

The consequence of this is that the following code will always set the value to add to the queue to `'item #1'`.

$form['insert_fieldset']['string_to_add'] = [
  '#type' => 'textfield',
  '#size' => 10,
  '#default_value' => $this->t('item @counter', ['@counter' => $form_state->get('insert_counter')]),
];
🐛 Bug report
Status

Fixed

Version

4.0

Component

Queue Example

Created by

🇸🇳Senegal ostry.sn

Live updates comments and jobs are added and updated live.
  • Needs reroll

    The patch will have to be re-rolled with new suggestions/changes described in the comments in the issue.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇮🇹Italy apaderno Brescia, 🇮🇹

    As a comment in the code says, he idea behind using a counter is to make entering a value for the string_to_add form element optional.
    Given that $queue->createItem() will always create a new item, even when it gets a value already used in a previous call, I think there is no need to use a counter to build a new queue item. The string_to_add form element should require a value, and that value should always be used to create a new queue item.

        $form['insert_fieldset']['string_to_add'] = [
          '#type' => 'textfield',
          '#required' => TRUE,
          '#size' => 10,
          '#default_value' => $this->t('Change me')]),
        ];
    

    It is not a bug entering two or more times the same value in the queue, since the purpose of that example form is adding to the queue whichever value entered for the string_to_add form element. The bug is that the code tries to use a different value for the default value of that form element, but that code ends up with using the same value as default value, for the reason said by @Miles23 in comment #2 🐛 'string_to_add' form element never increments Needs work .

    I agree with what said in that comment: There is no need to have a text field with an auto-incrementing value.

    Let's keep it simple: The string_to_add form element requires a value; whichever value is entered, that is added to the queue.
    Eventually, I would not accept a value that contains spaces or other non-visible characters.

  • Status changed to Needs review 4 months ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
    • apaderno committed 3ddcca23 on 4.0.x
      Issue #2978404: 'string_to_add' form element never increments
      
  • Status changed to Fixed 4 months ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024