You are here

class Maintenance200SettingsForm in Maintenance 200 8

Hierarchy

Expanded class hierarchy of Maintenance200SettingsForm

1 string reference to 'Maintenance200SettingsForm'
maintenance200.routing.yml in ./maintenance200.routing.yml
maintenance200.routing.yml

File

src/Form/Maintenance200SettingsForm.php, line 9

Namespace

Drupal\maintenance200\Form
View 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

Namesort descending Modifiers Type Description Overrides
ConfigFormBase::create public static function Instantiates a new instance of this class. Overrides FormBase::create 13
ConfigFormBase::__construct public function Constructs a \Drupal\system\ConfigFormBase object. 11
ConfigFormBaseTrait::config protected function Retrieves a configuration object.
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
FormBase::$configFactory protected property The config factory. 1
FormBase::$requestStack protected property The request stack. 1
FormBase::$routeMatch protected property The route match.
FormBase::configFactory protected function Gets the config factory for this form. 1
FormBase::container private function Returns the service container.
FormBase::currentUser protected function Gets the current user.
FormBase::getRequest protected function Gets the request object.
FormBase::getRouteMatch protected function Gets the route match.
FormBase::logger protected function Gets the logger for a specific channel.
FormBase::redirect protected function Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait::redirect
FormBase::resetConfigFactory public function Resets the configuration factory.
FormBase::setConfigFactory public function Sets the config factory for this form.
FormBase::setRequestStack public function Sets the request stack object to use.
FormInterface::getFormId public function Returns a unique string identifying the form. 236
LinkGeneratorTrait::$linkGenerator protected property The link generator. 1
LinkGeneratorTrait::getLinkGenerator Deprecated protected function Returns the link generator.
LinkGeneratorTrait::l Deprecated protected function Renders a link to a route given a route name and its parameters.
LinkGeneratorTrait::setLinkGenerator Deprecated public function Sets the link generator service.
LoggerChannelTrait::$loggerFactory protected property The logger channel factory service.
LoggerChannelTrait::getLogger protected function Gets the logger for a specific channel.
LoggerChannelTrait::setLoggerFactory public function Injects the logger channel factory.
Maintenance200SettingsForm::buildForm public function @inheritDoc Overrides ConfigFormBase::buildForm
Maintenance200SettingsForm::getEditableConfigNames protected function @inheritDoc Overrides ConfigFormBaseTrait::getEditableConfigNames
Maintenance200SettingsForm::getFormID public function @inheritDoc
Maintenance200SettingsForm::submitForm public function @inheritDoc Overrides ConfigFormBase::submitForm
Maintenance200SettingsForm::validateForm public function @inheritDoc Overrides FormBase::validateForm
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
RedirectDestinationTrait::$redirectDestination protected property The redirect destination service. 1
RedirectDestinationTrait::getDestinationArray protected function Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url.
RedirectDestinationTrait::getRedirectDestination protected function Returns the redirect destination service.
RedirectDestinationTrait::setRedirectDestination public function Sets the redirect destination service.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.
UrlGeneratorTrait::$urlGenerator protected property The url generator.
UrlGeneratorTrait::getUrlGenerator Deprecated protected function Returns the URL generator service.
UrlGeneratorTrait::setUrlGenerator Deprecated public function Sets the URL generator service.
UrlGeneratorTrait::url Deprecated protected function Generates a URL or path for a specific route based on the given parameters.