public function HttpStatusCode::evaluate in Context 8.4
Evaluates the condition and returns TRUE or FALSE accordingly.
Return value
bool TRUE if the condition has been met, FALSE otherwise.
Overrides ConditionInterface::evaluate
File
- src/
Plugin/ Condition/ HttpStatusCode.php, line 120
Class
- HttpStatusCode
- Provides a 'Http status code' condition.
Namespace
Drupal\context\Plugin\ConditionCode
public function evaluate() {
if (empty($this->configuration['status_codes']) && !$this
->isNegated()) {
return TRUE;
}
/** @var \Symfony\Component\HttpKernel\Exception\HttpException $exception */
$exception = $this->requestStack
->getCurrentRequest()->attributes
->get('exception');
if (!empty($exception) && $exception instanceof HttpException) {
$status_code = $exception
->getStatusCode();
}
else {
$status_code = 200;
}
return !empty($this->configuration['status_codes'][$status_code]);
}