Newer
Older
Angie Byron
committed
<?php
namespace Drupal\form_test;
use Drupal\Core\Form\ConfigFormBase;
Dries Buytaert
committed
use Drupal\Core\Form\FormStateInterface;
Angie Byron
committed
/**
* Provides a test form object.
*
* @internal
Angie Byron
committed
*/
class FormTestServiceObject extends ConfigFormBase {
Angie Byron
committed
/**
* {@inheritdoc}
Angie Byron
committed
*/
Alex Pott
committed
public function getFormId() {
Angie Byron
committed
return 'form_test_form_test_service_object';
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return ['form_test.object'];
}
Angie Byron
committed
/**
* {@inheritdoc}
Angie Byron
committed
*/
Dries Buytaert
committed
public function buildForm(array $form, FormStateInterface $form_state) {
$form['element'] = ['#markup' => 'The FormTestServiceObject::buildForm() method was used for this form.'];
Angie Byron
committed
$form['bananas'] = [
Angie Byron
committed
'#type' => 'textfield',
'#default_value' => 'brown',
'#title' => $this->t('Bananas'),
];
Angie Byron
committed
$form['actions']['#type'] = 'actions';
$form['actions']['submit'] = [
Angie Byron
committed
'#type' => 'submit',
'#value' => $this->t('Save'),
];
Angie Byron
committed
return $form;
}
/**
* {@inheritdoc}
Angie Byron
committed
*/
Dries Buytaert
committed
public function validateForm(array &$form, FormStateInterface $form_state) {
drupal_set_message($this->t('The FormTestServiceObject::validateForm() method was used for this form.'));
Angie Byron
committed
}
/**
* {@inheritdoc}
Angie Byron
committed
*/
Dries Buytaert
committed
public function submitForm(array &$form, FormStateInterface $form_state) {
drupal_set_message($this->t('The FormTestServiceObject::submitForm() method was used for this form.'));
$this->config('form_test.object', FALSE)
Alex Pott
committed
->set('bananas', $form_state->getValue('bananas'))
Angie Byron
committed
->save();
}
}