You are here

public function IefTest::buildForm in Inline Entity Form 8

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

tests/modules/inline_entity_form_test/src/IefTest.php, line 24

Class

IefTest
Tests Inline entity form element.

Namespace

Drupal\inline_entity_form_test

Code

public function buildForm(array $form, FormStateInterface $form_state, $form_mode = 'default', Node $node = NULL) {
  $form['inline_entity_form'] = [
    '#type' => 'inline_entity_form',
    '#entity_type' => 'node',
    '#bundle' => 'ief_test_custom',
    '#form_mode' => $form_mode,
  ];
  $form['submit'] = [
    '#type' => 'submit',
    '#value' => t('Save'),
  ];
  if (!empty($node)) {
    $form['inline_entity_form']['#default_value'] = $node;
    $form['submit']['#value'] = t('Update');
  }
  return $form;
}