3 namespace Drupal\form_test;
5 use Drupal\Core\Form\ConfigFormBase;
6 use Drupal\Core\Form\FormStateInterface;
7 use Symfony\Component\DependencyInjection\ContainerInterface;
8 use Symfony\Component\HttpFoundation\Request;
11 * Provides a test form object.
13 class FormTestControllerObject extends ConfigFormBase {
18 public function getFormId() {
19 return 'form_test_form_test_controller_object';
25 protected function getEditableConfigNames() {
26 return ['form_test.object'];
32 public static function create(ContainerInterface $container) {
33 drupal_set_message(t('The FormTestControllerObject::create() method was used for this form.'));
35 $container->get('config.factory')
42 public function buildForm(array $form, FormStateInterface $form_state, Request $request = NULL, $custom_attributes = NULL) {
43 $form['element'] = ['#markup' => 'The FormTestControllerObject::buildForm() method was used for this form.'];
45 $form['custom_attribute']['#markup'] = $custom_attributes;
46 $form['request_attribute']['#markup'] = $request->attributes->get('request_attribute');
49 '#type' => 'textfield',
50 '#title' => $this->t('Bananas'),
53 $form['actions']['#type'] = 'actions';
54 $form['actions']['submit'] = [
56 '#value' => $this->t('Save'),
64 public function validateForm(array &$form, FormStateInterface $form_state) {
65 drupal_set_message($this->t('The FormTestControllerObject::validateForm() method was used for this form.'));
71 public function submitForm(array &$form, FormStateInterface $form_state) {
72 drupal_set_message($this->t('The FormTestControllerObject::submitForm() method was used for this form.'));
73 $this->config('form_test.object')
74 ->set('bananas', $form_state->getValue('bananas'))