You are here

public function EntityAutocompleteElementFormTest::buildForm in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/src/Tests/Entity/Element/EntityAutocompleteElementFormTest.php \Drupal\system\Tests\Entity\Element\EntityAutocompleteElementFormTest::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/system/src/Tests/Entity/Element/EntityAutocompleteElementFormTest.php, line 88
Contains \Drupal\system\Tests\Entity\Element\EntityAutocompleteElementFormTest.

Class

EntityAutocompleteElementFormTest
Tests the EntityAutocomplete Form API element.

Namespace

Drupal\system\Tests\Entity\Element

Code

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