When having a block that must only be visible on a 200 status code the condition will always prematurely return FALSE since there is no exception.
if (!$this->requestStack->getCurrentRequest()->attributes->has('exception')) {
return FALSE;
}
I'm wondering if it's safe to assume that the status code is 200 if there's no exception. If yes, this could be handled pretty easily.
$config_response_codes = explode("\n", $response_code_list);
// Trim values.
$config_response_codes = array_map('trim', $config_response_codes);
// Create associative array.
$config_response_codes = array_combine($config_response_codes, $config_response_codes);
if (!$this->requestStack->getCurrentRequest()->attributes->has('exception') && isset($config_response_codes['200'])) {
return TRUE;
}
But I'm not sure how safe this is to just assume it that way.
| Comment | File | Size | Author |
|---|---|---|---|
| #8 | allow-block-visibility-200-response_3094793_8.patch | 1.76 KB | norman.lol |
Comments
Comment #2
norman.lolUpdated code snippet to trim array values. With an associative array you can also completely drop the foreach later and just use the following snippet.
Comment #3
norman.lolUpdated title.
Comment #4
norman.lolUpdated title.
Comment #5
norman.lolSimplified code.
Comment #6
norman.lolFixed typo.
Comment #7
norman.lolSorry for the multiple edits. Coding first in the text editor here on drupal.org is no good idea.
Comment #8
norman.lol