Problem/Motivation
#2362517: Improve default 403/404 exception HTML subscriber: don't duplicate the page render pipeline, use the routing system — add system.403 and system.404 routes adds a Http4xxController for returning 403 and 404 page markup.
In comment #12 @dawehner noted it would be good if these had their own theme functions to allow simple changes to the markup - e.g. #theme => 'page__403' or #theme => 'page__404'.
Proposed resolution
Add them
Remaining tasks
Wait for #2362517: Improve default 403/404 exception HTML subscriber: don't duplicate the page render pipeline, use the routing system — add system.403 and system.404 routes
Write patch.
Add tests.
Review.
User interface changes
None.
API changes
None.
Comment | File | Size | Author |
---|---|---|---|
#59 | 2363987-54-59.txt | 547 bytes | Krzysztof Domański |
#59 | 2363987-59.patch | 3.21 KB | Krzysztof Domański |
#36 | 2363987-36-40x-theme-suggestion-test-only.patch | 2.14 KB | mr.baileys |
Comments
Comment #1
catchComment #2
DuaelFrIs it still necessary?
With a Vanilla Drupal 8, templates suggestions follow the path so you can use html__system__40x or page__system__40x.
Comment #3
Crell CreditAttribution: Crell at Palantir.net commentedI'd much rather have a formal template defined than rely on magic path template naming. Path-based templating is a cludge anyway. :-) Not a priority but definitely open to someone working on this. I think this would also be 8.1 safe, probably?
Comment #4
dawehnerYeah, I think there would be no problem in making that an opt IN feature.
Comment #5
Wim LeersThis is just a matter of updating
\Drupal\system\Controller\Http4xxController
AFAICT.Comment #6
dawehnerYeah, you can also easily deal with it in a contrib module, if you like.
Comment #7
Crell CreditAttribution: Crell at Palantir.net commentedSo yes, consider this approved to work on whenever. :-)
Comment #11
acrosmanAttaching the patch from #2825147: No way to fully customise a 40x page by @chi.
Comment #12
Wim LeersI think this component is a better match.
Comment #13
IRONFELIX CreditAttribution: IRONFELIX commentedVery strange, I tried to use the patch #11, but drupal continue to ignore file "page--404.html.twig"
Comment #14
Chi CreditAttribution: Chi commented@IRONFELIX, I just checked it against the latest 8.4.x code. The patch is still valid. Make sure you clear caches and template name is spelled correctly.
Comment #15
IRONFELIX CreditAttribution: IRONFELIX commentedI use Drupal 8.3.1 and when I go to the wrong url, this line in code
returns value "entity.node.canonical" and next if doesn't work, of course.
Comment #16
Chi CreditAttribution: Chi commentedentity.node.canonical means that valid route was found for the requested URL.
Can you check how this works on fresh Drupal installation?
Comment #17
IRONFELIX CreditAttribution: IRONFELIX commented@Chi, to tell the truth, I decided to select more easy way and set hook in my theme without touching any system files::
Comment #18
Chi CreditAttribution: Chi commented@IRONFELIX, I suppose you have configured /node/49 path as default 404 page. That's why the patch did not work for you.
Comment #19
acrosmanComment #20
acrosmanComment #21
Pascal- CreditAttribution: Pascal- at Open Up Media commentedWorks perfectly.
Comment #22
Ruslan PiskarovHello @IRONFELIX.
Just try the following code together with
page--404.html.twig
:Comment #23
kovtunos CreditAttribution: kovtunos commented#22 Works for me. Tested on several sites (Drupal 8.3.5).
Comment #26
pingwin4egPatch from #2363987-11: Add theme support for content of 401/403/404 responses works perfectly already on 2 client's projects. Both - Drupal 8.4.x.
Comment #27
alexpottWe still need tests and a change record.
Comment #28
pawel_r CreditAttribution: pawel_r commentedI had to slightly change #22 answer to use another hook (hook_theme_suggestions_HOOK_alter):
Comment #29
acrosmanAdded a draft change record: https://www.drupal.org/node/2960810
Comment #30
kovtunos CreditAttribution: kovtunos as a volunteer commented$path_args variable is never used in #28. Here's updated code:
Comment #31
karenann CreditAttribution: karenann as a volunteer commentedFor those of us that want to keep the config items as an option, what do you all think of this as an option?
Comment #33
sankarprakash CreditAttribution: sankarprakash commented#17 - gives me a solution
Comment #34
Anonymous (not verified) CreditAttribution: Anonymous commentedGot a working solution with #30
Thanks for that!
Comment #36
mr.baileysAdded tests.
Comment #37
andypostinstead of
$this->container
better\Drupal::getContainer()
Comment #40
mr.baileysThanks @andypost, updated the test. Not sure why the test in #36 is failing, but seems unrelated to this change.
Comment #41
pandaski CreditAttribution: pandaski at govCMS (Australian Government Department of Finance) commentedBetter using
instead of
Also, another theme suggestion for `system.4xx` could be helpful as well.
Comment #42
mr.baileysUpdated the patch, taking into account the feedback from #41.
Comment #43
andypostNow ready!
Comment #44
pandaski CreditAttribution: pandaski at govCMS (Australian Government Department of Finance) commentedRTBC +1
Comment #45
lauriiiCould we add an assertion for the order of the suggestions as well? It would be good to ensure that the specific error codes override the generic one.
Comment #46
pandaski CreditAttribution: pandaski at govCMS (Australian Government Department of Finance) commentedComment #47
pandaski CreditAttribution: pandaski at govCMS (Australian Government Department of Finance) commentedCheck the suggestions
Comment #48
pandaski CreditAttribution: pandaski at govCMS (Australian Government Department of Finance) commentedComment #49
Krzysztof Domański1. Description for the @return value is missing.
2. Two spaces.
Comment #50
pandaski CreditAttribution: pandaski at govCMS (Australian Government Department of Finance) commentedreroll the patch with the comment from #49
Comment #51
Anonymous (not verified) CreditAttribution: Anonymous commentedComment #52
catchThis is using a data provider, so only one code is getting tested per method run. We could use a variable in the assertion message maybe? Or just remove the assertion message.
Comment #53
andypostComment #54
pandaski CreditAttribution: pandaski at govCMS (Australian Government Department of Finance) commentedThanks @catch
Attached patch contains the following changes:
Comment #55
Anonymous (not verified) CreditAttribution: Anonymous commentedComment #56
larowlanI think what @catch was asking here was for it to say
"Found expected suggestions for $route"
so it was more explicitOther than that, this looks good to go
Comment #57
larowlanActually, on second thoughts, lets just remove the message altogether.
The default provided by phpunit for arrays is far superior to anything we can come up with here.
Comment #58
larowlanFeel free to put it back to RTBC if the patch comes back green with that change
Comment #59
Krzysztof DomańskiChanges according to #57.
Comment #60
larowlanComment #61
larowlanCommitted ad5a6a6 and pushed to 8.8.x. Thanks!
Published change record
Comment #63
Wim LeersOh, wow! I'd swear this was done years ago, but clearly I was wrong!
Comment #64
andypostNext complimentary target is #2231853: Rename maintenance-page template into page--maintenance + install-page into page--maintenance--install
Comment #66
OCTOGONE.dev CreditAttribution: OCTOGONE.dev commented#22 Works for me.