Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form structure.

Overrides FormInterface::buildForm

File

core/modules/field_layout/tests/modules/field_layout_test/src/Form/EmbeddedForm.php, line 29

Class

EmbeddedForm
Provides the EmbeddedForm class.

Namespace

Drupal\field_layout_test\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $form['foo'] = [
    '#type' => 'fieldset',
    '#title' => $this
      ->t('Wrapper'),
    '#tree' => TRUE,
    '#parents' => [
      'foo',
    ],
  ];
  $entity = EntityTest::load(1);
  if ($entity) {
    if ($entity) {
      $display = EntityFormDisplay::collectRenderDisplay($entity, 'default');
      $subform_state = SubformState::createForSubform($form['foo'], $form, $form_state);
      $display
        ->buildForm($entity, $form['foo'], $subform_state);
      \Drupal::classResolver(FieldLayoutBuilder::class)
        ->buildForm($form['foo'], $display, $subform_state);
    }
  }
  return $form;
}