function EmbeddedForm::buildForm

Same name and namespace in other branches
  1. 11.x core/modules/field_layout/tests/modules/field_layout_test/src/Form/EmbeddedForm.php \Drupal\field_layout_test\Form\EmbeddedForm::buildForm()

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;
}

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