HTTPStatusCode.php in Zircon Profile 8
File
core/modules/views/src/Plugin/views/area/HTTPStatusCode.php
View source
<?php
namespace Drupal\views\Plugin\views\area;
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\HttpFoundation\Response;
class HTTPStatusCode extends AreaPluginBase {
protected function defineOptions() {
$options = parent::defineOptions();
$options['status_code'] = array(
'default' => 200,
);
return $options;
}
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
parent::buildOptionsForm($form, $form_state);
$options = Response::$statusTexts;
$options = array(
'404' => $options['404'],
'403' => $options['403'],
'500' => $options['500'],
) + $options;
array_walk($options, function ($title, $code) use (&$options) {
$options[$code] = $this
->t('@code (@title)', array(
'@code' => $code,
'@title' => $title,
));
});
$form['status_code'] = array(
'#title' => $this
->t('HTTP status code'),
'#type' => 'select',
'#default_value' => $this->options['status_code'],
'#options' => $options,
);
}
function render($empty = FALSE) {
if (!$empty || !empty($this->options['empty'])) {
$build['#attached']['http_header'][] = [
'Status',
$this->options['status_code'],
];
return $build;
}
}
}