FormTestServiceObject.php in Zircon Profile 8
Same filename and directory in other branches
Contains \Drupal\form_test\FormTestServiceObject.
Namespace
Drupal\form_testFile
core/modules/system/tests/modules/form_test/src/FormTestServiceObject.phpView source
<?php
/**
* @file
* Contains \Drupal\form_test\FormTestServiceObject.
*/
namespace Drupal\form_test;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
/**
* Provides a test form object.
*/
class FormTestServiceObject extends ConfigFormBase {
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'form_test_form_test_service_object';
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'form_test.object',
];
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$form['element'] = array(
'#markup' => 'The FormTestServiceObject::buildForm() method was used for this form.',
);
$form['bananas'] = array(
'#type' => 'textfield',
'#default_value' => 'brown',
'#title' => $this
->t('Bananas'),
);
$form['actions']['#type'] = 'actions';
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => $this
->t('Save'),
);
return $form;
}
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
drupal_set_message($this
->t('The FormTestServiceObject::validateForm() method was used for this form.'));
}
/**
* {@inheritdoc}
*/
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)
->set('bananas', $form_state
->getValue('bananas'))
->save();
}
}
Classes
Name | Description |
---|---|
FormTestServiceObject | Provides a test form object. |