PluginFormInterface is implemented by plugins to allow them to provide a partial form as part of a larger form.
They do not have their own form IDs and they are not individually run through hook_form_alter().

Since plugins can be reused in many different parent forms, a module wishing to alter a plugin's form must be aware of all cases in which that plugin is used. This is difficult to do correctly and extremely burdensome to maintain.

Proposed resolution

Introduce a specific alter for plugin subforms.

Remaining tasks

Decide on naming
Improve docs on PluginFormInterface

User interface changes


API changes

N/A, best practice change only.
Instead of directly calling buildConfigurationForm() and validate/submit directly, use the PluginFormManager (name TBD)

Data model changes


Members fund testing for the Drupal project. Drupal Association Learn more


tim.plunkett created an issue. See original summary.

tim.plunkett’s picture

Status: Active » Needs review
23.74 KB
EclipseGc’s picture

I REALLY like this. It makes all plugin forms available to be altered regardless of where they're used so long as they go through this new class. Major ++ to it.


samuel.mortenson’s picture

Per an in-chat conversation, we should verify that there are enough API additions here to enable a module like Block Class to generically add configuration and form elements for a "class" text field.

Currently this patch makes it possible to alter plugin forms, but adding submit or validate callbacks, which are required to set plugin configuration values, is not possible as the plugin form is traditionally nested inside another form (i.e. it's not top-level, so you couldn't add $form['#submit'] in your plugin-level form alter).

We should think about adding additional hooks when plugins are validated or submit, or support a new key like #plugin_submit/#plugin_validate.

EclipseGc’s picture

Yeah, I'd prefer to see something like that at the subformstate level. It'd be nice if we could, as part of normal validation/submission, just invoke validate/submit handlers of the subformstate. Not sure how viable that is though.


tim.plunkett’s picture

I definitely want to think through the SubformState part of this more. It'd be so awesome to have the ability to get that SubformState back in validate/submit, instead of having to recreate it.

In the meantime, this would allow easier adding of handlers (sort of...)