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

CommentFileSizeAuthor
#2 2795959-1.patch4.38 KBwebflo
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

webflo created an issue. See original summary.

webflo’s picture

FileSize
4.38 KB

I tried so read from form_state in most cases, because $this->getSetting() does not hold the updated form value during form rebuild.

dawehner’s picture

Status: Active » Fixed

Thank you!

  • dawehner committed bd1d8e5 on 8.x-1.x authored by webflo
    Issue #2795959 by webflo: Formatter settings lost during ajax callback
    

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.