
| Current Path : /var/www/html/rocksensor1/web/core/modules/views/src/Plugin/views/area/ |
Linux ift1.ift-informatik.de 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 |
| Current File : /var/www/html/rocksensor1/web/core/modules/views/src/Plugin/views/area/HTTPStatusCode.php |
<?php
namespace Drupal\views\Plugin\views\area;
use Drupal\Core\Form\FormStateInterface;
use Drupal\views\Attribute\ViewsArea;
use Symfony\Component\HttpFoundation\Response;
/**
* Alter the HTTP response status code used by the view.
*
* @ingroup views_area_handlers
*/
#[ViewsArea("http_status_code")]
class HTTPStatusCode extends AreaPluginBase {
/**
* {@inheritdoc}
*/
protected function defineOptions() {
$options = parent::defineOptions();
$options['status_code'] = ['default' => 200];
return $options;
}
/**
* {@inheritdoc}
*/
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,
];
}
/**
* {@inheritdoc}
*/
public function render($empty = FALSE) {
if (!$empty || !empty($this->options['empty'])) {
$build['#attached']['http_header'][] = ['Status', $this->options['status_code']];
return $build;
}
}
}