Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. HTTPStatusCode.php

function HTTPStatusCode::buildOptionsForm

Overrides AreaPluginBase::buildOptionsForm

File

core/modules/views/src/Plugin/views/area/HTTPStatusCode.php, line 31

Class

HTTPStatusCode
Alter the HTTP response status code used by the view.

Namespace

Drupal\views\Plugin\views\area

Code

public function buildOptionsForm(&$form, FormStateInterface $form_state) {
    parent::buildOptionsForm($form, $form_state);
    // Get all possible status codes defined by symfony.
    $options = Response::$statusTexts;
    // Move 403/404/500 to the top.
    $options = [
        '404' => $options['404'],
        '403' => $options['403'],
        '500' => $options['500'],
    ] + $options;
    // Add the HTTP status code, so it's easier for people to find it.
    array_walk($options, function ($title, $code) use (&$options) {
        $options[$code] = $this->t('@code (@title)', [
            '@code' => $code,
            '@title' => $title,
        ]);
    });
    $form['status_code'] = [
        '#title' => $this->t('HTTP status code'),
        '#type' => 'select',
        '#default_value' => $this->options['status_code'],
        '#options' => $options,
    ];
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal