I am utilizing a AJAX type. This kind I construct from a sub-class of ContentEntityForm
. Drupal Development Company Entity edited by this manner has a subject MyField. To deliver all Drupal Development Service subject values in a applicable construction I am utilizing massageFormValues()
in MyFieldWidget
class (sub-class of WidgetBase
).
Drupal Development Company little downside is: Drupal Development Service technique massageFormValues()
is known as twice on each submit. Drupal Development Company are not any different issues with Drupal Development Service type. I can correctly edit values on this manner.
So it is simply Drupal Development Service query of understanding: why Drupal do name massageFormValues()
twice on each submit.
Drupal Development Company talked about and my (very simplified) code:
My ajax controller
class AjaxController extends ControllerBase { ... ... public perform myController($eid) { $myEntity = $this->entityTypeManager()->getStorage('my_entity')->load($eid); $type = $this->entityFormBuilder()->getForm($myEntity, 'my_mode'); $renderer = Drupal::service('renderer'); $output = $renderer->renderRoot($type); $response = new AjaxResponse(); $response->addCommand(new OpenModalDialogCommand($title, $output)); return $response; } ... ... }
MyForm
is a sub-class of Drupal Development Service ContentEntityForm and it is a mode type for Drupal Development Service mode my_mode
of Drupal Development Service Entity my_entity
:
class MyForm extends ContentEntityForm { ... ... protected perform actions(array $type, FormStateInterface $form_state) { $actions = mum or dad::actions($type, $form_state); $actions['submit'] = [ '#type' => 'submit', '#value' => t('Save'), '#ajax' => [ 'callback' => '::ajaxCallback', 'event' => 'mousedown', ], ]; return $actions; } ... ... }
My subject widget class:
class MyFieldWidget extends WidgetBase implements ContainerFactoryPluginInterface { ... ... public perform massageFormValues(array $values, array $type, FormStateInterface $form_state) { // THIS CODE IS CALLED TWICE ON EVERY SUBMIT OF MY SUBMIT BUTTON DEFINED ABOVE // BUT WHY TWICE? return $rightStructureValues; } ... ... }