0

In the QueueExampleForm.php) file, which is part of the Examples for Developers project, why does $form_state->get('insert_counter') always return an empty value after the form has been submitted and an item was inserted into the queue?

5
  • Cross-posted on drupal.org/project/examples/issues/2978404
    – leymannx
    Commented Jun 11, 2018 at 11:51
  • @Clive – Would this make this question off-topic then as well?
    – leymannx
    Commented Jun 11, 2018 at 12:29
  • 1
    @leymannx Pings only work if someone was on the comment/post. We tends to avoid crossposting across SE, but tolerate (to an extent) crossposts to D.O. What we don't want are bug reports here.
    – mpdonadio
    Commented Jun 11, 2018 at 18:48
  • @mpdonadio, the reason why I first come here was because in my opinion Drupal official examples code should be something well tested before putting that in the official repository. Because lot of people take it naturally as a Bible!!! But now, I think really that it is a bug and non my misunderstanding.
    – ostry.sn
    Commented Jun 12, 2018 at 1:58
  • @ostry.sn No worries. I think this is a good question here.
    – mpdonadio
    Commented Jun 12, 2018 at 12:36

3 Answers 3

0

I think it's a bug. So in order to keep the incrementing textfield. we can remove the setting/getting of the useless arbitrary property "insert_counter" and exploit the call of existing instruction :

$items = $this->retrieveQueue($queue_name);

In resume, we can just replace :

'#default_value' => $this->t('item @counter', ['@counter' => $form_state->get('insert_counter')]),
by
'#default_value' => $this->t('item @counter', ['@counter' => count($items) + 1]),

And remove the $form_state->setRebuild(); inside the addqueue submit handler

-1

Lets try with

$form_State->getValue('insert_counter');

or

$form_State->get('insert_counter')->getValue();
1
  • In fact, "insert_counter" is not a field form, but an arbitral property set dynamically
    – ostry.sn
    Commented Jun 12, 2018 at 18:26
-1

I think try below code

$textfield_1 = $form_state->getValue('insert_counter');  //'#tree' => TRUE
 $values = $form_state->getValues(); // '#tree' => TRUE
1
  • In fact, "insert_counter" is not a field form, but an arbitral property set dynamically
    – ostry.sn
    Commented Jun 12, 2018 at 18:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.