class Maintenance200SettingsForm in Maintenance 200 8
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
- class \Drupal\maintenance200\Form\Maintenance200SettingsForm
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
Expanded class hierarchy of Maintenance200SettingsForm
1 string reference to 'Maintenance200SettingsForm'
File
- src/
Form/ Maintenance200SettingsForm.php, line 9
Namespace
Drupal\maintenance200\FormView source
class Maintenance200SettingsForm extends ConfigFormBase {
/**
* @inheritDoc
*/
public function getFormID() {
return 'maintenance200_settings';
}
/**
* @inheritDoc
*/
protected function getEditableConfigNames() {
return [
'maintenance200.settings',
];
}
/**
* @inheritDoc
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this
->config('maintenance200.settings');
$form['explanation'] = [
'#type' => 'markup',
'#markup' => 'Here, you can enable or disable the maintenance200 status code change functionality, and also set the status code that will be used if the functionality is enabled.',
];
$form['maintenance200_enabled'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Change the status code during maintenance mode'),
'#default_value' => $config
->get('maintenance200_enabled'),
];
$form['maintenance200_status_code'] = [
'#type' => 'textfield',
'#title' => $this
->t('Status code to use'),
'#maxlength' => '3',
'#size' => '3',
'#required' => TRUE,
'#description' => $this
->t('A valid HTTP status code is required. See the Wikipedia <a href="http://en.wikipedia.org/wiki/List_of_HTTP_status_codes">HTTP status codes</a> page for a complete list.'),
'#default_value' => $config
->get('maintenance200_status_code'),
];
return parent::buildForm($form, $form_state);
}
/**
* @inheritDoc
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
parent::validateForm($form, $form_state);
if ($form_state
->getValue('maintenance200_status_code')) {
$http_status_codes = [
100 => 'Continue',
101 => 'Switching Protocols',
102 => 'Processing',
200 => 'OK',
201 => 'Created',
202 => 'Accepted',
203 => 'Non-Authoritative Information',
204 => 'No Content',
205 => 'Reset Content',
206 => 'Partial Content',
207 => 'Multi-Status',
300 => 'Multiple Choices',
301 => 'Moved Permanently',
302 => 'Found',
303 => 'See Other',
304 => 'Not Modified',
305 => 'Use Proxy',
306 => 'Switch Proxy',
307 => 'Temporary Redirect',
400 => 'Bad Request',
401 => 'Unauthorized',
402 => 'Payment Required',
403 => 'Forbidden',
404 => 'Not Found',
405 => 'Method Not Allowed',
406 => 'Not Acceptable',
407 => 'Proxy Authentication Required',
408 => 'Request Timeout',
409 => 'Conflict',
410 => 'Gone',
411 => 'Length Required',
412 => 'Precondition Failed',
413 => 'Request Entity Too Large',
414 => 'Request-URI Too Long',
415 => 'Unsupported Media Type',
416 => 'Requested Range Not Satisfiable',
417 => 'Expectation Failed',
418 => 'I\'m a teapot',
422 => 'Unprocessable Entity',
423 => 'Locked',
424 => 'Failed Dependency',
425 => 'Unordered Collection',
426 => 'Upgrade Required',
449 => 'Retry With',
450 => 'Blocked by Windows Parental Controls',
500 => 'Internal Server Error',
501 => 'Not Implemented',
502 => 'Bad Gateway',
503 => 'Service Unavailable',
504 => 'Gateway Timeout',
505 => 'HTTP Version Not Supported',
506 => 'Variant Also Negotiates',
507 => 'Insufficient Storage',
509 => 'Bandwidth Limit Exceeded',
510 => 'Not Extended',
];
if (!array_key_exists($form_state
->getValue('maintenance200_status_code'), $http_status_codes)) {
$form_state
->setErrorByName('maintenance200_status_code', $this
->t('A valid HTTP status code is required.'));
}
}
else {
$form_state
->setErrorByName('maintenance200_status_code', $this
->t('You must provide an HTTP status code.'));
}
}
/**
* @inheritDoc
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$this
->config('maintenance200.settings')
->set('maintenance200_enabled', $form_state
->getValue('maintenance200_enabled'))
->set('maintenance200_status_code', $form_state
->getValue('maintenance200_status_code'))
->save();
parent::submitForm($form, $form_state);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigFormBase:: |
public static | function |
Instantiates a new instance of this class. Overrides FormBase:: |
13 |
ConfigFormBase:: |
public | function | Constructs a \Drupal\system\ConfigFormBase object. | 11 |
ConfigFormBaseTrait:: |
protected | function | Retrieves a configuration object. | |
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
FormBase:: |
protected | property | The config factory. | 1 |
FormBase:: |
protected | property | The request stack. | 1 |
FormBase:: |
protected | property | The route match. | |
FormBase:: |
protected | function | Gets the config factory for this form. | 1 |
FormBase:: |
private | function | Returns the service container. | |
FormBase:: |
protected | function | Gets the current user. | |
FormBase:: |
protected | function | Gets the request object. | |
FormBase:: |
protected | function | Gets the route match. | |
FormBase:: |
protected | function | Gets the logger for a specific channel. | |
FormBase:: |
protected | function |
Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait:: |
|
FormBase:: |
public | function | Resets the configuration factory. | |
FormBase:: |
public | function | Sets the config factory for this form. | |
FormBase:: |
public | function | Sets the request stack object to use. | |
FormInterface:: |
public | function | Returns a unique string identifying the form. | 236 |
LinkGeneratorTrait:: |
protected | property | The link generator. | 1 |
LinkGeneratorTrait:: |
protected | function | Returns the link generator. | |
LinkGeneratorTrait:: |
protected | function | Renders a link to a route given a route name and its parameters. | |
LinkGeneratorTrait:: |
public | function | Sets the link generator service. | |
LoggerChannelTrait:: |
protected | property | The logger channel factory service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
Maintenance200SettingsForm:: |
public | function |
@inheritDoc Overrides ConfigFormBase:: |
|
Maintenance200SettingsForm:: |
protected | function |
@inheritDoc Overrides ConfigFormBaseTrait:: |
|
Maintenance200SettingsForm:: |
public | function | @inheritDoc | |
Maintenance200SettingsForm:: |
public | function |
@inheritDoc Overrides ConfigFormBase:: |
|
Maintenance200SettingsForm:: |
public | function |
@inheritDoc Overrides FormBase:: |
|
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
UrlGeneratorTrait:: |
protected | property | The url generator. | |
UrlGeneratorTrait:: |
protected | function | Returns the URL generator service. | |
UrlGeneratorTrait:: |
public | function | Sets the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Generates a URL or path for a specific route based on the given parameters. |