Introduce hook_plugin_subform_alter() for use with PluginFormInterface

Created on 13 February 2018, over 6 years ago
Updated 7 August 2023, 10 months ago

Problem/Motivation

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

N/A

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

N/A

πŸ“Œ Task
Status

Needs work

Version

11.0 πŸ”₯

Component
PluginΒ  β†’

Last updated about 16 hours ago

Created by

πŸ‡ΊπŸ‡ΈUnited States tim.plunkett Philadelphia

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • The Needs Review Queue Bot β†’ tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

    Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

    Consult the Drupal Contributor Guide β†’ to find step-by-step guides for working with issues.

  • @timplunkett opened merge request.
  • πŸ‡ΊπŸ‡ΈUnited States tim.plunkett Philadelphia

    Opened an MR with the code from #6

  • πŸ‡«πŸ‡·France Grimreaper France πŸ‡«πŸ‡·

    Hi,

    Thanks a lot for the issue and the work done here.

    I am encountering the problem in https://www.drupal.org/project/ui_styles β†’ for the sub modules.

    Currently we have ui_styles_layout_builder that allows to add CSS classes to the rendering of blocks and layouts used in Layout Builder but on the long term we would like to have:
    - ui_styles_block: for blocks either in Layout Builder or in Structure > block layout
    - ui_styles_layout: for layouts anywhere it is used, Layout Builder, view modes, Page Manager, etc.

    And I think it may also introduce a great potential of refactoring of https://www.drupal.org/project/layout_options β†’ to not have to provide a dedicated layout class.

    I don't know if it is out-of-scope of this issue, currently the issue is focused on (sub)form alter / validation / submission. But what happens after new configuration is saved? How do I use generically the newly/altered configuration?

    For blocks and layouts, it is the build() method that is used but it may have a different name in other plugin types. Maybe a first distinction could be "rendering" plugin types, and then the other plugin types?

    The subject may be too massive and may have to be splitted into dedicated issues. First this one handling configuration form will be a huge step forward.

Production build 0.69.0 2024