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

Command icon 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

aaronbauman created an issue. See original summary.

aaronbauman’s picture

Issue summary: View changes
bojanz’s picture

Your 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.

aaronbauman’s picture

Title: PluginConfiguration::processPluginConfiguration, when called upon form validate and form submit, instantiates an empty plugin instead of using form values » How to get original configuration values during PluginConfiguration::processPluginConfiguration ?
Category: Bug report » Support request

I 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?

TomTech made their first commit to this issue’s fork.

tomtech’s picture

Status: Active » Needs review

  • jsacksick committed d3130d03 on 8.x-2.x authored by TomTech
    Issue #3021571 by AaronBauman: How to get original configuration values...
jsacksick’s picture

Category: Support request » Bug report
Status: Needs review » Fixed

Thanks a lot for the fix Tom, merged!

  • jsacksick committed a8676502 on 3.0.x authored by TomTech
    Issue #3021571 by AaronBauman: How to get original configuration values...

Status: Fixed » Closed (fixed)

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