function EntityAutocompleteElementFormTest::buildForm

Same name in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Entity/Element/EntityAutocompleteElementFormTest.php \Drupal\KernelTests\Core\Entity\Element\EntityAutocompleteElementFormTest::buildForm()
  2. 10 core/tests/Drupal/KernelTests/Core/Entity/Element/EntityAutocompleteElementFormTest.php \Drupal\KernelTests\Core\Entity\Element\EntityAutocompleteElementFormTest::buildForm()
  3. 11.x core/tests/Drupal/KernelTests/Core/Entity/Element/EntityAutocompleteElementFormTest.php \Drupal\KernelTests\Core\Entity\Element\EntityAutocompleteElementFormTest::buildForm()

Overrides FormInterface::buildForm

File

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

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

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