You are here

public function EntityAutocompleteElementFormTest::buildForm in Drupal 10

Same name and namespace in other branches
  1. 8 core/tests/Drupal/KernelTests/Core/Entity/Element/EntityAutocompleteElementFormTest.php \Drupal\KernelTests\Core\Entity\Element\EntityAutocompleteElementFormTest::buildForm()
  2. 9 core/tests/Drupal/KernelTests/Core/Entity/Element/EntityAutocompleteElementFormTest.php \Drupal\KernelTests\Core\Entity\Element\EntityAutocompleteElementFormTest::buildForm()

File

core/tests/Drupal/KernelTests/Core/Entity/Element/EntityAutocompleteElementFormTest.php, line 107

Class

EntityAutocompleteElementFormTest
Tests the EntityAutocomplete Form API element.

Namespace

Drupal\KernelTests\Core\Entity\Element

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $form['single'] = [
    '#type' => 'entity_autocomplete',
    '#target_type' => 'entity_test',
  ];
  $form['single_autocreate'] = [
    '#type' => 'entity_autocomplete',
    '#target_type' => 'entity_test',
    '#autocreate' => [
      'bundle' => 'entity_test',
    ],
  ];
  $form['single_autocreate_specific_uid'] = [
    '#type' => 'entity_autocomplete',
    '#target_type' => 'entity_test',
    '#autocreate' => [
      'bundle' => 'entity_test',
      'uid' => $this->testAutocreateUser
        ->id(),
    ],
  ];
  $form['tags'] = [
    '#type' => 'entity_autocomplete',
    '#target_type' => 'entity_test',
    '#tags' => TRUE,
  ];
  $form['tags_autocreate'] = [
    '#type' => 'entity_autocomplete',
    '#target_type' => 'entity_test',
    '#tags' => TRUE,
    '#autocreate' => [
      'bundle' => 'entity_test',
    ],
  ];
  $form['tags_autocreate_specific_uid'] = [
    '#type' => 'entity_autocomplete',
    '#target_type' => 'entity_test',
    '#tags' => TRUE,
    '#autocreate' => [
      'bundle' => 'entity_test',
      'uid' => $this->testAutocreateUser
        ->id(),
    ],
  ];
  $form['single_no_validate'] = [
    '#type' => 'entity_autocomplete',
    '#target_type' => 'entity_test',
    '#validate_reference' => FALSE,
  ];
  $form['single_autocreate_no_validate'] = [
    '#type' => 'entity_autocomplete',
    '#target_type' => 'entity_test',
    '#validate_reference' => FALSE,
    '#autocreate' => [
      'bundle' => 'entity_test',
    ],
  ];
  $form['single_access'] = [
    '#type' => 'entity_autocomplete',
    '#target_type' => 'entity_test',
    '#default_value' => $this->referencedEntities[0],
  ];
  $form['tags_access'] = [
    '#type' => 'entity_autocomplete',
    '#target_type' => 'entity_test',
    '#tags' => TRUE,
    '#default_value' => [
      $this->referencedEntities[0],
      $this->referencedEntities[1],
    ],
  ];
  $form['single_string_id'] = [
    '#type' => 'entity_autocomplete',
    '#target_type' => 'entity_test_string_id',
  ];
  $form['tags_string_id'] = [
    '#type' => 'entity_autocomplete',
    '#target_type' => 'entity_test_string_id',
    '#tags' => TRUE,
  ];
  return $form;
}