class HTTPStatusCode
Same name and namespace in other branches
- 11.x core/modules/views/src/Plugin/views/area/HTTPStatusCode.php \Drupal\views\Plugin\views\area\HTTPStatusCode
Alter the HTTP response status code used by the view.
Plugin annotation
@ViewsArea("http_status_code");
Hierarchy
- class \Drupal\Component\Plugin\PluginBase extends \Drupal\Component\Plugin\PluginInspectionInterface, \Drupal\Component\Plugin\DerivativeInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait implements \Drupal\Component\Plugin\PluginBase
- class \Drupal\views\Plugin\views\PluginBase extends \Drupal\Core\Plugin\ContainerFactoryPluginInterface, \Drupal\views\Plugin\views\ViewsPluginInterface, \Drupal\Component\Plugin\DependentPluginInterface, \Drupal\Core\Security\TrustedCallbackInterface implements \Drupal\Core\Plugin\PluginBase
- class \Drupal\views\Plugin\views\HandlerBase extends \Drupal\views\Plugin\views\ViewsHandlerInterface implements \Drupal\views\Plugin\views\PluginBase
- class \Drupal\views\Plugin\views\area\AreaPluginBase implements \Drupal\views\Plugin\views\HandlerBase
- class \Drupal\views\Plugin\views\area\HTTPStatusCode implements \Drupal\views\Plugin\views\area\AreaPluginBase
- class \Drupal\views\Plugin\views\area\AreaPluginBase implements \Drupal\views\Plugin\views\HandlerBase
- class \Drupal\views\Plugin\views\HandlerBase extends \Drupal\views\Plugin\views\ViewsHandlerInterface implements \Drupal\views\Plugin\views\PluginBase
- class \Drupal\views\Plugin\views\PluginBase extends \Drupal\Core\Plugin\ContainerFactoryPluginInterface, \Drupal\views\Plugin\views\ViewsPluginInterface, \Drupal\Component\Plugin\DependentPluginInterface, \Drupal\Core\Security\TrustedCallbackInterface implements \Drupal\Core\Plugin\PluginBase
- class \Drupal\Core\Plugin\PluginBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait implements \Drupal\Component\Plugin\PluginBase
Expanded class hierarchy of HTTPStatusCode
Related topics
File
-
core/
modules/ views/ src/ Plugin/ views/ area/ HTTPStatusCode.php, line 15
Namespace
Drupal\views\Plugin\views\areaView source
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;
}
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.