class FormTestObject

Provides a test form object.

Hierarchy

Expanded class hierarchy of FormTestObject

2 files declare their use of FormTestObject
FormObjectTest.php in drupal/core/modules/system/lib/Drupal/system/Tests/Form/FormObjectTest.php
Contains \Drupal\system\Tests\Form\FormObjectTest.
form_test.module in drupal/core/modules/system/tests/modules/form_test/form_test.module
Helper module for the form API tests.
1 string reference to 'FormTestObject'
form_test.routing.yml in drupal/core/modules/system/tests/modules/form_test/form_test.routing.yml
drupal/core/modules/system/tests/modules/form_test/form_test.routing.yml

File

drupal/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/FormTestObject.php, line 15
Contains \Drupal\form_test\FormTestObject.

Namespace

Drupal\form_test
View source
class FormTestObject implements FormInterface {

  /**
   * Implements \Drupal\Core\Form\FormInterface::getFormID().
   */
  public function getFormID() {
    return 'form_test_form_test_object';
  }

  /**
   * Implements \Drupal\Core\Form\FormInterface::buildForm().
   */
  public function buildForm(array $form, array &$form_state) {
    $form['element'] = array(
      '#markup' => 'The FormTestObject::buildForm() method was used for this form.',
    );
    $form['bananas'] = array(
      '#type' => 'textfield',
      '#title' => t('Bananas'),
    );
    $form['actions']['#type'] = 'actions';
    $form['actions']['submit'] = array(
      '#type' => 'submit',
      '#value' => t('Save'),
    );
    return $form;
  }

  /**
   * Implements \Drupal\Core\Form\FormInterface::validateForm().
   */
  public function validateForm(array &$form, array &$form_state) {
    drupal_set_message(t('The FormTestObject::validateForm() method was used for this form.'));
  }

  /**
   * Implements \Drupal\Core\Form\FormInterface::submitForm().
   */
  public function submitForm(array &$form, array &$form_state) {
    drupal_set_message(t('The FormTestObject::submitForm() method was used for this form.'));
    config('form_test.object')
      ->set('bananas', $form_state['values']['bananas'])
      ->save();
  }

}

Members