Problem/Motivation

Currently the "Plugin selector" functionality is tied to a field widget. It would be nice to have a form element that may be used in any form to select and configure plugins. This element can then be reused in the plugin selector widget.

Proposed resolution

  • Create form element plugin with plugin selector functionality
  • Reuse new form element in plugin selector field widget plugin

Remaining tasks

  • Discussion about possible caveats when providing the plugin selector functionality as form element
  • Create plugin selector form element plugin
  • Rework field widget plugin to use plugin selector form element
  • User interface changes

    n/a

    API changes

    • New "Plugin selector" form element will be available for non-entity forms

    Data model changes

    n/a

    Issue fork plugin-3197304

    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

    hctom created an issue. See original summary.

    hctom’s picture

    Issue summary: View changes
    hctom’s picture

    Issue summary: View changes
    joachim’s picture

    That's a good idea.

    Have a look at src/Element/PluginConfiguration.php in Commerce module. We should work towards converging with the plugin support in Commerce with a view to getting something into core eventually.

    hctom’s picture

    Title: Provide form element ans reuse that in field widget » Provide form element and reuse that in field widget

    joachim’s picture

    Status: Active » Needs work

    Got something working!

    Enable the test module and go to /configured-plugin-form-element to see it in action.

    It produces a complete plugin selection with configuration form element for just this in your form:

        $form['plugin'] = [
          '#type' => 'configured_plugin',
          '#title' => $this->t('Plugin'),
          '#plugin_type' => 'condition',
          '#required' => TRUE,
          // '#default_value' => [
            //   'plugin_id' => ,
            //   'plugin_configuration' => $action_link->get('plugin_config'),
            // ],
          ];
    

    Still to do:

    - tests!
    - make the field widget use it
    - maybe identify which plugins can't use this? So far I've found the field plugins won't work because the plugins have a nonstandard constructor.

    milos.kroulik made their first commit to this issue’s fork.

    milos.kroulik’s picture

    I've tried to fix minor issues. Hopefully it makes sense.

    joachim’s picture

    Thanks for your fixes to the branch @milos.kroulik !

    I'll look at the issues you've raised when I have more time.

    joachim’s picture

    Until this gets committed, copying the class into a module and hardcoding a few things is a viable option :D

    https://git.drupalcode.org/project/computed_field/-/blob/4.0.x/src/Eleme...