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?
-
Cross-posted on drupal.org/project/examples/issues/2978404– leymannxCommented Jun 11, 2018 at 11:51
-
@Clive – Would this make this question off-topic then as well?– leymannxCommented 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.snCommented 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
Add a comment
|
3 Answers
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
Lets try with
$form_State->getValue('insert_counter');
or
$form_State->get('insert_counter')->getValue();
-
In fact, "insert_counter" is not a field form, but an arbitral property set dynamically– ostry.snCommented Jun 12, 2018 at 18:26
I think try below code
$textfield_1 = $form_state->getValue('insert_counter'); //'#tree' => TRUE
$values = $form_state->getValues(); // '#tree' => TRUE
-
In fact, "insert_counter" is not a field form, but an arbitral property set dynamically– ostry.snCommented Jun 12, 2018 at 18:26