Now we have FormInterface, I'd like to suggest we add an EmbeddedFormInterface to make it easier and more consistent to embed form snippets in forms. Use cases are where plugins can offer form elements to use in a form of the module they are plugins of, such as the payment methods for Payment and Drupal Commerce.
That sounds hot.
- Crell on IRC
Proposal:
<?php
namespace Drupal\Core\Form;
/**
* Provides an interface for an embedded form snippet.
*/
interface EmbeddedFormInterface {
/**
* Form snippet constructor.
*
* @param array $form
* An associative array containing the structure of the main form.
* @param array $form_state
* An associative array containing the current state of the main form.
* @param array $parents
* The array keys of parent elements in $form.
*
* @return array
* The form snippet structure.
*/
public function buildForm(array $form, array &$form_state, array $parents);
/**
* Form snippet validation handler.
*
* @param array $form
* An associative array containing the structure of the form snippet.
* @param array $form_state
* An associative array containing the current state of the form snippet.
* @param array $parents
* The array keys of parent elements in $form.
*/
public function validateForm(array &$form, array &$form_state, array $parents);
}
?>