interface SubformStateInterface

Same name and namespace in other branches
  1. 11.x core/lib/Drupal/Core/Form/SubformStateInterface.php \Drupal\Core\Form\SubformStateInterface
  2. 10 core/lib/Drupal/Core/Form/SubformStateInterface.php \Drupal\Core\Form\SubformStateInterface
  3. 8.9.x core/lib/Drupal/Core/Form/SubformStateInterface.php \Drupal\Core\Form\SubformStateInterface

Stores information about the state of a subform.

In the context of Drupal's Form API, a subform is a form definition array that will be nested into a "parent" form. For instance:

$subform = [
  'method' => [
    '#type' => 'select',
  ],
];
$form = [
  // …
'settings' => $subform,
];

All input fields nested under "settings" are then considered part of that "subform". The concept is used mostly when the subform is defined by a different class (potentially even in a different module) than the parent form. This is often the case for plugins: a plugin's buildConfigurationForm() would then be handed an instance of this interface as the second parameter.

The benefit of doing this is that the plugin can then just define the form – and use the form state – as if it would define a "proper" form, not nested in some other form structure. This means that it won't have to know the key(s) under which its form structure will be nested – for instance, when retrieving the form values during form validation or submission.

Contrary to "proper" forms, subforms don't translate to a <form> tag in the HTML response. Instead, they can only be discerned in the HTML code by the nesting of the input tags' names.

Hierarchy

Expanded class hierarchy of SubformStateInterface

All classes that implement SubformStateInterface

See also

\Drupal\Core\Plugin\PluginFormInterface::buildConfigurationForm()

4 files declare their use of SubformStateInterface
CKEditor5.php in core/modules/ckeditor5/src/Plugin/Editor/CKEditor5.php
ConditionPluginBase.php in core/lib/Drupal/Core/Condition/ConditionPluginBase.php
InlineBlock.php in core/modules/layout_builder/src/Plugin/Block/InlineBlock.php
SubformStateTest.php in core/tests/Drupal/Tests/Core/Form/SubformStateTest.php

File

core/lib/Drupal/Core/Form/SubformStateInterface.php, line 42

Namespace

Drupal\Core\Form
View source
interface SubformStateInterface extends FormStateInterface {
  
  /**
   * Gets the complete form state.
   *
   * @return \Drupal\Core\Form\FormStateInterface
   */
  public function getCompleteFormState();

}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.