Observed symptom
Upon submission of plugin edit form, an existing plugin configuration is missing.
All configuration is in default state.
Specifically, this is the cause of #2971197: When updating the configuration form your password gets wiped.
Culprit
\Drupal\commerce\Element\PluginConfiguration::processPluginConfiguration(), when called upon submitting a form, instantiates a plugin using values from $element['#default_value'], which is an empty array.
Suggested resolution
During form submission, plugins should be instantiated with values from $element['#value'] instead of $element['#default_value']
Tasks
- Post a failing test. Here's what should suffice to demonstrate the issue:
- Test module that implements the commerce plugin interface
- Plugin instance with a configuration form that has hidden data
- Browser test which submits the configuration form for an existing plugin instance, unchanged
- Assert that the saved config matches the original config <- this should fail
- Confirm expectations that for test with maintainers
- Post the patch for PluginConfiguration::processPluginConfiguration
- Review, revise, rinse, repeat
Issue fork commerce-3021571
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
aaronbaumanComment #3
bojanz commentedYour suggestion sounds like the opposite of what we want (and have).
The plugin is always supposed to be instantiated with the original configuration, since the changed configuration is still in form state, waiting to be processed.
But maybe I'm missing something.
Comment #4
aaronbaumanI think what we figured out in the thread (#2971197) is that it's just really ugly to get the original configuration:
$form_state->getBuildInfo()['callback_object']->getEntity()->getPlugin()->getConfiguration();Does this look right?
Or have we made it harder than it needs to be?
Comment #7
tomtech commentedComment #9
jsacksick commentedThanks a lot for the fix Tom, merged!