2

I have a form that lists entities and each of the entities has a checkbox. The form also contains a list of actions(Action plugin) that can be performed on selected entities as a select list.

I would like to be able to configure actions that extend the \Drupal\Core\Action\ConfigurableActionBase class, which means they are configurable, right in my form since some actions can have very different settings and creating action entity for each variation of those setting is just impossible. I would create a new action entity from those settings, without saving it, and use it to perform the action(although I could do it just with the plugin, but that's not important right now).

I am able to retrieve the form elements for those configurable actions and display them in my form. The issue I have is that incorporating those elements into form is tricky on its own, but validating and submitting them is on another level since I cannot just encapsulate those form elements under some specific form array/key because the validation and submit handler for those plugins will not work with that.

The \Drupal\Core\Plugin\PluginFormInterface::buildConfigurationForm() is not a proper D8 form but it just holds the form elements so it's not like I am trying to embed a form within another form, but it is stillquite impossible as I am seeing it right now.

So how can I do this? Or can you recommend a different approach?

This is the initial design: http://pastebin.com/b8SCFvUQ

1 Answer 1

1

I have solved this by making sure my forn had a unique element names to avoid collision with the Action's configuration. I have added a 'x_' prefix to names of all my elements. Since my form did not use #tree globally I have put the Action's configuration under a 'configruation' key and in form validation and submit callbacks I have provided this array as $form['configuration'] to the validation and submit handlers of the Action plugin instead of the whole $form array. So far it works withotu any issues.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.