As far as I can see, we currently only call the configurationFormValidate() and configurationFormSubmit() methods for plugins that actually have a non-empty form.

However, in #2414425-3: Value changes in form validation not saved when server is added Darren Oh argued:

I think a developer who writes a validation method would expect it to run.

I, myself, wouldn't think that. There's nothing to validate and submit, so why would these be called?
Granted, there might be situations where someone wants to put other code there as a mild "hack" – but then they can just use a dummy form with a single value element to ensure the validation method is called. I don't think the situation arises often enough that we have to cater more for it.

On the other hand, after a quick browse, Core doesn't seem to do this anywhere, they always call the method regardless of whether the form is actually non-empty. Which makes our behavior non-standard, which we should of course avoid.
However, they're mitigating this somewhat, at least in most cases, by not including PluginFormInterface in their specific plugin interface – and then check for each plugin whether it implements that interface, assuming then (quite naturally) that the appropriate methods should be called. I think that this is a quite sensible compromise – you don't have to have a form if you just need the validation (or submission) method, but if you don't need any of them those won't be called unnecessary either.
Of course, this would need to be well documented, to ensure that plugin implementers are aware of this behavior – something that Core, as far as I can see, once again ignores.

So, opening the floor, what is everyone's opinion on this?

The decision could then also be implemented in Drupal 7 (as long as we don't go the route via the separate PluginFormInterface) – and there, we also have the possibility to properly document it if the method isn't called in all circumstances (which we can hardly do when we're using a Core interface).

Estimated Value and Story Points

This issue was identified as a Beta Blocker for Drupal 8. We sat down and figured out the value proposition and amount of work (story points) for this issue.

Value and Story points are in the scale of fibonacci. Our minimum is 1, our maximum is 21. The higher, the more value or work a certain issue has.

Value : 2
Story Points: 5

Comments

drunken monkey’s picture

Regarding Drupal 8, I just had to tinker around in that area again. The problem was that during index form validation/submission, the used entity already contained the new values, which broke the logic in the plugins (which already had the new settings when submitConfigurationForm() was called, thus not being able to recognize whether any values were changed).
I was confused, because this seems to have changed in Core, but this behavior doesn't really seem to make sense to me for other plugin systems, either.

So, there's another question in this area: should we use Core's behavior here, or continue with the more complicated workaround I implemented now? (Suggestions for implementing this more cleanly are, of course, welcome in any case.) In the former case, we'd just have to update the ContentEntity datasource as well, to manually load the old index to find out whether the settings changed. (Or come up with a completely different system for reacting to such changes.)

nick_vh’s picture

Issue summary: View changes
Issue tags: +beta blocker
drunken monkey’s picture

Status: Active » Needs review
StatusFileSize
new6.8 KB

This only adds tests (and already fixes two issues discovered that way) to ensure we don't break things while re-writing this.

Status: Needs review » Needs work

The last submitted patch, 3: 2445251-3--plugin_validation_and_submission_logic.patch, failed testing.

drunken monkey’s picture

Regarding how to actually re-write this, I see two options:

  1. Keep things (mostly) as they are.
    • I.e., call the validate/submit methods only if there is a form.
    • Just fix the @todos in IndexForm to make this consistent for datasources and trackers, too.
    • Maybe override the methods in our interface to add this to their description.
  2. Be consistent with Core.
    • Remove PluginFormInterface from our ConfigurablePluginInterface.
    • Document that plugins with forms need to implement the interface themselves to have their form-related methods get called.
    • Move our default implementations from the plugin base class to a trait (maybe/probably excluding the form builder method itself).
    • Check for the interface and only depend on that for whether we call those methods.
    • … anything else?

Since no-one else really seems to have an opinion here, I'm gonna go with 2. and implement that. But input is still welcome, we can still go with 1. or some other variant.

drunken monkey’s picture

Status: Needs work » Needs review
StatusFileSize
new1.88 KB
new6.87 KB

Oops, didn't consider that.

drunken monkey’s picture

This might already work. No time to test though, since they're now kicking us out. :(
(Stable release delayed another week!)

drunken monkey’s picture

Even if tests pass, still needs visual confirmation of all the plugin forms – especially both with and without Javascript enabled.

Status: Needs review » Needs work

The last submitted patch, 7: 2445251-7--plugin_validation_and_submission_logic.patch, failed testing.

drunken monkey’s picture

Status: Needs work » Needs review
StatusFileSize
new905 bytes
new37.67 KB

Why didn't PhpStorm report that as an error?!?
Resulted in a fatal error when run (since there is an interface with the same name in the trait's own namespace).

Status: Needs review » Needs work

The last submitted patch, 10: 2445251-10--plugin_validation_and_submission_logic.patch, failed testing.

drunken monkey’s picture

Status: Needs work » Needs review
StatusFileSize
new15.16 KB
new46.2 KB

This took incredible long, but it should finally be working.
(Also confirmed manually, both with and without Javascript.)

  • drunken monkey committed bcd85f5 on 8.x-1.x
    Issue #2445251 by drunken monkey: Fixed plugin form validation/...
drunken monkey’s picture

Status: Needs review » Fixed

A review would've been great, but I wouldn't want to review that mess of a patch either.
So, since the tests also pass and seem to cover this pretty well, I'll just commit this now and we hope for the best/wait for complaints.

Status: Fixed » Closed (fixed)

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