Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
Problem/Motivation
I had some trouble configuring the formatter, because it lost some state during the ajax callback.
[17:31:41] <webflo> dawehner_: FieldFormatterWithInlineSettings handles the form state wrong during formatter configuration. is it possible to write to $this->setSetting() in an ajax callback? or should wird initialize form state once. and read always from form_state.
[17:34:06] <webflo> http://cgit.drupalcode.org/field_formatter/tree/src/Plugin/Field/FieldFormatter/FieldFormatterWithInlineSettings.php#n199 the formatter switches back to the inital $formatted_field_name if the triggering element is a different element
[17:34:15] <webflo> not the field_name dropdown itself
[17:34:29] <dawehner_> webflo: ah, so we should actually look stuff up in $form_state->input?
[17:34:43] <webflo> yeah or $form_state->value
[17:35:09] <webflo> because $this->getSetting() does hold the updated value after the ajax call
[17:35:16] <webflo> does *not*
[17:37:14] <dawehner_> webflo: well $form_state->value just works after an actual form submit, doesn't it?
[17:40:42] <webflo> i think it works because of rebuildSubmit,
[17:40:57] webflo is confused
[17:41:59] <dawehner_> webflo: ah yeah could be
[17:42:31] <dawehner_> webflo: I just always try to do any kind of serious work as part of the ajax callback. It has bitten me too many times in the past
Proposed resolution
Remaining tasks
User interface changes
API changes
Data model changes
Comment | File | Size | Author |
---|---|---|---|
#2 | 2795959-1.patch | 4.38 KB | webflo |
Comments
Comment #2
webflo CreditAttribution: webflo at UEBERBIT GmbH commentedI tried so read from form_state in most cases, because $this->getSetting() does not hold the updated form value during form rebuild.
Comment #3
dawehnerThank you!