Problem/Motivation
In system_theme_suggestions_maintenance_page(), a template suggestion is provided for maintenance-page--offline.html.twig:
if ($offline) {
$suggestions[] = 'maintenance_page__offline';
}
However, this template is not picked up when the system is offline. This results in a generic, unstyled exception page (i.e. a WSOD), creating a poor user experience. This is functionality that did exist and work in Drupal 7, and an attempt was made to have this functionality ported to Drupal 8, but appears to not have been completed/successful.
This is a major issue because it has no workaround and is a regression from Drupal 7.
Cause a significant admin- or developer-facing bug with no workaround.
Steps to reproduce
Scenario A (when core/includes/errors.inc is used):
- Set correct database credentials in settings.php
- Clear cache: drush cr
- Set $config['system.logging']['error_level'] = 'hide' in settings.php
- Set $settings['maintenance_theme'] = 'bartik' in settings.php
- Set incorrect database credentials in settings.php (for example invalid username)
- Refresh the page.
- There is a plain text message: "The website encountered an unexpected error. Please try again later."
Scenario B (when \Drupal\Core\EventSubscriber\FinalExceptionSubscriber is used):
- Make sure that $settings['hash_salt'] in set in settings.php
- Clear cache: drush cr
- Set $config['system.logging']['error_level'] = 'hide' in settings.php
- Set $settings['maintenance_theme'] = 'bartik' in settings.php
- Comment out $settings['hash_salt'] in settings file
- Refresh the page.
- There is a plain text message: "The website encountered an unexpected error. Please try again later."
Proposed resolution
Adds a way to render a template when in a fatal error context first by trying to get the maintenance theme in settings and then by the slower extension discovery if the that fails. Finally it falls back to a WSOD like fatal message.
Scenario A is addressed by calling the new static method in errors.inc.
Scenario B is addressed by calling the new static method in FinalExceptionSubscriber.
These scenarios are addressed in a new browser test.
Remaining tasks
User interface changes
Fatal errors will be attempted to be rendered using the maintenance theme "offline" template. This would cause previously displaying a WSOD to potentially show a themed page instead.
API changes
- New public method Drupal\Core\Utility\Error::renderFatalError
Data model changes
N/A
Release notes snippet
This is a patch (bugfix) for a regression due to incomplete porting of functionality from Drupal 7 to Drupal 8 (and now Drupal 9). Drupal 7 allowed for the implementation of maintenance-page--offline.tpl.php, a template that to be shown when the site was offline and unable to connect to the database. The porting of this functionality to Drupal 8 and 9 was incomplete, and the equivalent Twig template, maintenance-page--ofline.html.twig, was not picked up, resulting in a generic, unstyled exception page (i.e. a WSOD) with a poor user experience. This but has now been fixed, and site themers can implement maintenance-page--ofline.html.twig on Drupal 8 and 9 sites.
Who this affects
This bugfix affects Drupal theme developers. Theme developers will now be able to create a template page to be displayed when Drupal is unable to reach the database, providing an improved user experience.
How to Implement
- Copy core/modules/system/templates/maintenance-page.html.twig to the theme to be used when your site is offline.
- (Optional) Edit the template to provide the HTML you would like visitors to see when the site is offline
- Edit settings.php, uncomment the line
$settings['maintenance_theme'] = 'bartik';, and change the value frombartikto the machine name of the theme you chose in step one above. - Clear your registry
How to test the template
After performing the steps above, the way to test that the template is working is to force a fatal error on your site. Warning: it is strongly advised to not test this on a production server. Fatal errors can be forced as follows:
- Set
$config['system.logging']['error_level'] = 'hide';in settings.php - Set incorrect database credentials in settings.php (for example invalid username)
- Refresh the page
- Confirm that the template has been picked up
| Comment | File | Size | Author |
|---|---|---|---|
| #155 | 2720109-155.maintenance-page.patch | 22.34 KB | hmdnawaz |
| #145 | 2720109-145.maintenance-page.patch | 22.34 KB | hmdnawaz |
| #142 | 2720109-142.maintenance-page.patch | 22.39 KB | jrb |
| #135 | 2720109-135.patch | 22.44 KB | nigelcunningham |
| #123 | interdiff-2720109-121-123.txt | 1.03 KB | yogeshmpawar |
Issue fork drupal-2720109
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
kiwimind commentedSeeing the same thing here and haven't found a way to get it to work yet.
There's a suggestion in
system_theme_suggestions_maintenance_pagein core/modules/system/system.module, which looks like it should work, but doesn't.Comment #3
niklp commentedYeah this does look like a bug of sorts, the folks in #drupal-uk tried all sorts of things and couldn't get a template working, even putting a forced template in core/modules/system/templates
Comment #4
seppelM commentedLike I wrote, fatal errors are directly output without any "rendering",
except within the installation process → install_display_output() which calls drupal_maintenance_theme()
(@see errors.inc ~ 251)
- Maybe a plain .html file, to get around non-catchable needed services like Twig or dependent ones?
- otherwise render the --offline.html.twig which is enriched with "static" twig template variables or $config (settings.php)?
Comment #5
seppelM commentedAny update on this issue?
Comment #6
jenny.cha commentedHi there,
Has anyone found an alternative way to create a custom offline maintenance page? Since this bug has been reported, there has not been an update for 7 months, so I'm curious as to if anyone else found a solution.
Thanks!
Comment #7
jenny.cha commentedHas anyone found an alternative solution to create a custom offline maintenance page? There hasn't been an update on this issue for about 7 months now...
Comment #8
cilefen commentedComment #10
jaypanChanging the status to major, as the system outputs a WSOD in the case of a fatal error, which is horrible UI. This fits into the status description for major due to this:
This is a significant bug and there is no workaround at the moment.
Comment #11
ekl1773Comment #12
zeutyFirst of all, steps to reproduce the issue.
Situation A (when core/includes/errors.inc is used):
1. Set incorrect database credentials in settings file.
2. Refresh the page.
Situation B (when core/lib/Drupal/Core/EventSubscriber/FinalExceptionSubscriber is used):
1. Comment out $settings['hash_salt'] in settings file
2. Refresh the page.
The patch adds a possibility to have a twig template that styles fatal errors described in A and B.
Comment #13
zeutyComment #15
ivan berezhnov commentedComment #18
jaypanI tested the patch in #12, unfortunately it does not work with 8.8.
Comment #19
jungleComment #20
felribeiro commentedPatch to the 8.9.x-dev
Comment #21
felribeiro commentedPatch to the 8.9.x-dev
Comment #24
mradcliffeI performed Novice Triage on this issue. I am leaving the Novice tag on this issue because I think that we still need to update the issue summary here to make it clear what the steps to reproduce. Also we sould run this through Major issue triage and update the issue accordingly that would be great. Particularly we should also analyze based on Allowed changes in major and minor releases.
Comment #25
freed_paris commentedHello,
This patch doesn't work anymore with Drupal 8.8.4 (or maybe earlier after 8.7.x)
Any solution ?
Thanks
Comment #26
jaypanComment #27
jaypanComment #28
jaypanComment #29
neslee canil pintoRerolled the patch, Please review
Comment #30
neslee canil pintoComment #32
jaypanI tested the patch from #30 on Drupal 8.8.4, and it did not work.
Comment #33
dcam commentedThank you for your contribution, @Neslee Canil Pinto, but your two patches were incomplete. My guess is that since the template file was new it didn't get added to the Git diff.
I'm adding the Needs Reroll tag back. Whoever makes another attempt at this, make sure you reroll #21, not #29 or #30. Also, make sure you add the template to the diff.
Comment #34
bthompson1 commentedI installed a clean site with drupal 8.9.x-dev as well as 8.4.4. The maintenance page loads without a problem with bartik. I even have twig debug enabled and the source code is showing the correct template file being used. Is this an issue with other themes? It's not clear why a patch is needed at this point. I can help with this issue but I'm unable to reproduce the error originally noted based on the information provided. If anyone can provide more details that would be helpful. Thanks.
Comment #35
jaypanbthompson1
Did you follow the steps to reproduce?
Comment #36
bthompson1 commentedComment #37
andrey.troeglazov commentedI have tested patch from #21 with 8.9.x-dev and 8.8.x-dev and it works for me.
So why does it need to be rerolled?
Comment #38
bthompson1 commentedI agree, #21 works. #30 doesn't work as it's missing the template file.
Comment #39
piyuesh23 commentedComment #40
jaypanI just tested the patch in 21. It is an improvement on the existing UX, giving an error page, versus the default error message (or nothing) on the WSOD.
However, the template file is named incorrectly. The system is expecting the template file maintenance-page--offline.html.twig, as outlined in the opening post, but the patch is using fatal-error-page.html.twig. So this still needs some work.
Definitely better than the current core default though.
Comment #41
bthompson1 commentedIf a site is throwing fatal errors, which is what is happening in the steps to reproduce, then this really has nothing to do with maintenance mode in my opinion. I consider these separate issues and see a fatal error template as reasonable.
Comment #42
jaypanMaybe that's a separate issue then.
The current issue is about maintenance-mode--offline.html.twig not being picked up, functionality that was part of D7, whose implementation was only partially completed in D8.
Maybe for that issue, but it does not solve the current issue.
Comment #43
sharma.amitt16 commented@Jaypan, I have modified patch #21. Removed dependency on Bartik's theme added in #21.
Now all the fatal errors are themable. Now anyone can override the maintenance offline template in their theme.
I hope this is what you are addressing in this issue.
@NOTE: Don't use this patch instead use patch #47.
Comment #44
sharma.amitt16 commentedComment #45
jungleCleanup tags, `drupal core` is unnecessary and IS updated, Rerolled.
Comment #47
sharma.amitt16 commentedComment #49
bthompson1 commentedIf you look at the code for system_theme_suggestions_maintenance_page it checks a constant to determine if the site is in maintenance mode. This is when processes like update and authorize are running. Only then will the page template maintenance-mode--offline.html.twig ever be picked up.
The steps to reproduce the issue are not valid as they don't result in the site site being "offline". Instead they are fatal errors which have nothing to do with the MAINTENANCE_MODE indicator.
I'm not even sure why there's a need for an offline template. you need to put your site in maintenance mode for the offline template to ever be picked up. And it would seem that if you are running processes to update your site the maintenance page template should suffice.
Comment #50
jaypanYou’ll have to go back and find out the rationale on it. Nevertheless it’s functionality that existed in D7, but the migration to D8 is incomplete leaving this functionality broken.
Comment #51
sharma.amitt16 commentedI agree with @bthompson1, it is advised to keep the site in maintenance mode before doing update activity.
But I believe @jaypan is reporting about the fatal error messages (like 500, website encountered an error with backtrace messages) which render as an unformatted text on the browser. He is talking about the templatizing of these error messages. Also, I think this is not related to offline mode. @jaypan, would you please confirm if I am not wrong.
If it is related to templatizing of error messages only then patch #47 is working fine for different fatal error messages that occurred on the site. Also after applying this patch, you can customize the template in your custom theme.
@NOTE: If it is not related to maintenance mode then the naming convention of template Is a point of discussion. What name should be given to the template?
Comment #52
sharma.amitt16 commentedModifications for test case failure.
Comment #54
sharma.amitt16 commentedComment #57
sharma.amitt16 commentedModified the patch for test case failure.
@NOTE: Please review Patch #54, as it is not compatible.
Comment #59
sharma.amitt16 commentedComment #60
sharma.amitt16 commentedComment #62
sharma.amitt16 commentedComment #63
mradcliffeIt looks like there are test failures so the correct status is Needs work. We probably also need to add some tests so I added the Needs tests tag.
I am leaving the Novice tag on this issue because it is still fairly clear what the next steps are.
It may also help to clarify the intent of the issue in the issue summary based on the discussion in earlier comments.
Comment #64
sharma.amitt16 commentedComment #65
mradcliffeAdding Global2020 and Bug Smash Initiative tags to hopefully move the issue forward. See my previous comments.
Comment #66
maacl commentedI would like to propose to use the offline theme from the settings.php instead of trying to get the active theme. In my testing I always got "seven" as active theme, so this should be more reliable.
I also added escaping of the error message and removed deprecated code.
Comment #67
maacl commentedFixing tests. BigBipe explicitly expects the error message to not contain a
<body>-Tag. The Error does contain this tag after applying the patch. So I removed the assertion.Comment #68
quietone commentedThere is still work to do here, see #63.
Comment #70
shaktikwoking same patch on 9.2.x. Tested on local.
Comment #71
mradcliffeI performed Novice Triage on this issue. I am leaving the Novice tag on this issue because I think that we can work on this together to add a test to the latest patch in order to assert the regression.
Bump back to Needs work because we should add a test for the patch since this is a regression. @shaktik, you can add a test run manually to a patch that is in Needs work without needing to change it.
Also I added the Needs issue summary tag because as it took a while to (re-)familiarize myself with what has happened so far in the issue. I think having a proposed resolution section to describe what we have done (code-wise) to resolve the issue.
Comment #72
kndrI've changed "Steps to reproduce" slightly since there are two "main players" we should consider: error_level and maintenance_theme. In the test cases I suggest to focus on 'error_level = hide' because we should examine system behavior from a user point of view above all.
Comment #73
kndrMy review and a new patch proposal
Comment #74
kndrI can't resist thoughts that this issue is just a 'feature request'. We don't get WSOD in 9.2.x any longer. All proposed changes lead to replace plain text message with a Twig template.
Comment #75
kndrLet's try this patch. FinalExceptionSubscriber sends a html response if a request format is html and a plain text otherwise.
Comment #76
kndrA small fix to pass a testExpectedScaffoldFiles.
Comment #77
kndr#76 patch is green so review is appreciated.
Comment #78
jaypanTested and confirmed - the template is correctly picked up for both the test cases outlined in the issue outline. Thanks for the nice work!
Comment #79
spokjeTag clean-up and back to NW for
Needs Tests(#63)(IS was updated in #45)
Lemme see if I can make a failing test for both scenarios that passes with patch #76
Comment #80
spokjeSo I've managed to create a test for Scenario A in the IS (Change DB credentials.
I've attached that to patch#76 and as a test_only_should_fail patch.
For scenario B I've tried something similar:
but that doesn't work for TestBot.
Since reading the salt_hash happens very early in the bootstrap phase, changing it afterwards has an effect when doing actual request, but TestBot doesn't notice the change.
I've tried uncommenting
drupal_flush_all_caches();in the example above, but that throws an uncaughtRuntimeException, which is an automatic fail for TestBot :/Somebody with a bigger (Test Writing) brain than mine has to look at this.
Comment #81
spokjeLeaving at "Needs work" because there's still no test for Scenario B as described in the Issue Summary.
Comment #82
spokjePlease ignore the test_only patch from #80, this is the correct one.
Comment #83
kndr@Spokje, Thanks for your tests. They inspired me a lot. I tried hard to figured it out how to write an automated test when there is no 'hash_salt' value in a settings.php file. It turned out that you were really close to solve it. Function drupal_flush_all_caches() should be called before rewriting settings. The same situation is described in "Steps to reproduce". We should clear a cache first and than refresh a page. Besides this, I've added additional test cases because we should check if a maintenance theme's template is picked up when it exists in a 'template' directory. I hope it is OK now but review is appreciated.
Comment #85
jaypanWas 2720109-83-test-only.patch supposed to fail?
Comment #86
kndrYes, 2720109-83-test-only.patch should fail. It replicates "Steps to reproduce" and proves that system without a 2720109-83.patch has a bug.
Comment #87
kndrThe idea of 'test-only' patches is explained at a step #10 on a page https://www.drupal.org/contributor-tasks/write-tests
Comment #88
spokjeRemoved `Needs Tests`-tag since tests are here (thanks @kndr!🙏).
Since I myself worked on this issue I can't make it RTBC, but the quick scan I did on the code looks promising.
Comment #89
jaypanThank you, appreciated.
I don't have a testing system set up, or the time to do so, to be able to test it myself. When I do, I will, if no one has.
Comment #90
kndr@Jaypan Can you mark this issue RTBC? There is a nice cheat sheet and a sample comment http://www.kristen.org/content/my-drupal-issue-queue-rtbc-cheat-sheet Thanks.
Comment #91
jaypanI'm matching RTBC as:
* Patch applies cleanly.
* Tests pass.
* Test-only patch fails as expected.
* No coding standard problems were found by the test bot.
* Code is clear and addresses the issue from the issue summary.
* New test code tests the specific issue from the issue summary.
* Feedback from previous comments has been addressed.
* Issue title is clear and relevant.
* The issue summary properly clarifies the issue
* Issue metadata looks okay.
* Manually tested and patch works as expected.
Comment #93
quietone commentedReuploading the patch in #83 because the fail patch is being tested every two days.
Comment #94
alexpottThe comment shoudl wrap at 80 chars/
This can be removed if we call
$listing->setProfileDirectories([]);after constructing the $listing object and before scanning.This has the potential to be randomly correct. I would take the current username and add a longer random string to it. Or something like that.
If the drupal_flush_all_caches() is necessary it need a comment as to why. I'm not sure it is necessary.
Comment #95
kndr@alexpott, thank you for the review. You are absolutely right so I've made changes you suggested. As for the point 3 I decided to change the user password since it is impossible to set it correctly in this way. It turned out that drupal_flush_all_caches() was not necessary in an automated test but flushing the cache is necessary during manual testing 'hash_salt'. BTW, is it still valid to attach a test-only patch? If it is being tested every two days as @quietone said at #93 maybe test-only patch should be omitted?
Comment #97
renatog commentedIn this case:
Please could you use "inside of"? E.g.:
Comment #99
jaypanIf we're doing wording, I think "located at" is natural.
Comment #100
renatog commentedI agree
Comment #101
spokjeFirst a reroll of patch #95.
Comment #102
spokjeAddressed #97/#99
Comment #105
spokjeUsed
2720109-102.patchas base for the MR against9.3.x/code>Comment #106
quietone commentedCame to do a review.
I started reading the Issue Summary. It is really nice to have steps to reproduce, A and B. However, there are no remaining tasks or proposed resolution. Without a proposed resolution it is not possible to confirm that the patch here is doing what it should be. Note that #71 also asked for a proposed resolution section to be added. Tagging for an issue summary update and keeping the novice tag, I think updating the IS for this issue is a suitable novice task.
Then I read the issue. And then I got very confused about when the maintenance mode template is to be used. See #34, #41 and #49, all of which did not, in my opinion receive an explanation. Perhaps the reason is in the IS where is says that Drupal 7 behaved this way. I don't know if that is true, but if it is it is a regression. If I understand correctly, this is using the maintenance mode twig file when the site is deliberately placed in maintenance mode and when a fatal error occurs. The IS just says that this is to use the twig file when the site is offline and when I think 'offline' I think maintenance mode not fatal. If that is correct the IS can state that more clearly. I am not doing that in case I am wrong.
This issue also should have before and after screenshots.
No time left for a code review.
Edit: s/the/then/
Comment #107
kndrAs I mentioned at #74 I see this issue more as "feature request" than "bug report". The issue priority is too high as well. I can agree that maintenance mode has nothing in common with handling fatal errors. The whole work that was done in this issue was focused on rendering fatal error page from twig template. That's all. I vote for changing the category to "feature request", priority to "normal" and topic to "Render fatal error page from twig template" or so. The last patch can handle this new feature but it uses a little confusing template's name (maintenance-page--offline.html.twig) in the new context.
Comment #108
quietone commented@kndr, thank you! I was so focused on getting my head around this issue that I didn't even think about the issue category and priority.
I agree with kndr and have implemented the suggestions in #107.
Setting to NW to change the template name to something that reflects what the template is for.
Comment #109
jaypanThis is a bug. It's behavior from Drupal 7 that was not ported to Drupal 8, containing documentation that indicates the template will be picked up and it is not. As this bug causes a fatal error with a WSOD, it is a major bug.
Comment #110
kndr@jaypan Are you sure that it causes a fatal error with WSOD? Neither "Situation A" nor "Situation B" described in "Steps to reproduce" ends with WSOD. As a result we have a plain text message: "The website encountered an unexpected error. Please try again later." so it works as designed. Can you check this out manually in your environment? Maybe we missed something that causing WSOD. If so I can agree that this is a "bug report". Otherwise I'm pretty sure that this is "feature request".
Comment #111
jaypanReplace WSOD with 'fatal error' then. My point still stands that it's a bug, and that it shuts down your site with no control over the site builder to theme the page. This is a major bug.
This is where I disagree. As the original post lays out, it was designed to pick up a TWIG template
named maintenance-page--offline.html.twig. Drupal 7 allowed formaintenance-page--offline.tpl.php, however this functionality was not properly implemented in Drupal 8, and the corresponding twig template is not picked up, as it was designed to. Hence this thread is a bug report, not a feature request.Comment #112
jaypanComment #113
jwilson3This is definitely a bug, not a feature request. The maintenance_page__offline template suggestion is not the only thing impacted by the broken render pipeline when a fatal issue is encountered.
There is also a Twig variable
db_offlineavailable in thehtml.html.twigtemplate supplied by core, but there is no practical way to make use of this Twig variable.Comment #114
mradcliffeI performed Novice Triage on this issue. I am leaving the Novice tag on this issue because I think there is a good contribution opportunity for manual testing without a local environment to provide before/after screenshots that @quietone requested above. You should be able to do both Scenario A and Scenario B using DrupalPod.
I reviewed the current merge request and took a stab at providing the current proposed resolution and removed the Needs issue summary update tag.
I also added the Needs release note because this is a Major bug fix that site owners should be aware of. I'm not sure if that also means it needs a Change record or not.
Comment #115
jaypanI've added a release note. I personally don't think a changelog is necessary, as this isn't a change, it's a bugfix. That said, I don't know the criteria for determining whether a changelog should be written, so I may be out of line on that.
Comment #116
jaypanI'm wondering if we should add an item to remaining tasks for writing a documentation page equivalent to Theming the Drupal maintenance page. The linked page contains the D7 documentation for using maintenance-page--offline.tpl.php.
Comment #117
jaypanComment #118
jaypanComment #120
joey-santiago commentedI did my best to reroll the patch on 9.3.x and here's the result.
I think there's something a little bit off with the way the template is looked up maybe? If i set my custom theme as maintenance in settings.php:
and i put my template in: web/themes/contrib/mytheme/templates/system/maintenance-page--offline.html.twig
it is not picked up. It only gets picked up if i put it in: web/themes/contrib/mytheme/templates/maintenance-page--offline.html.twig
This is not a huge deal, but it threw me off, because i have my "normal" maintenance page template in web/themes/contrib/mytheme/templates/system/maintenance-page.html.twig and that works correctly.
Comment #121
ranjith_kumar_k_u commentedRe-rolled #120 for 9.4
Comment #123
yogeshmpawarUpdated patch will fix the test failure.
Comment #125
yogeshmpawarComment #126
shashwat purav commentedThe patch in #123 applied successfully to 9.4.x branch.
Comment #127
jaypanComment #128
tonytheferg commentedPatch works well. I used #121 because #123 would not apply to 9.3.9 via composer, and I didn't fell like requiring dev. Thanks!
Comment #129
hmdnawaz commentedI applied the patch, and it works.
But I am unable to override the
maintenance-page--offline.html.twigtemplate in my theme.I copied the file to
/themes/custom/mytheme/templates/system/maintenance-page--offline.html.twig, cleared the cache, but Drupal still displays the template from the system module instead of my theme.Updated:
It is working in
/themes/custom/mytheme/templates/maintenance-page--offline.html.twigComment #130
joey-santiago commentedHave you set your theme as maintenance mode theme in settings.php @hmdnawaz?
$settings['maintenance_theme'] = 'yourtheme';Comment #131
hmdnawaz commented@joey-santiago
I checked it with with and without that setting,
But now I place the template file directly in the templates directory without a system directory and it works without that setting
in the settings.php.
Comment #132
alexpottI think this should detail the expected keys. Ie. title, content and displayable and say what they are. Or I wonder if instead of $context we should have 3 parameters.
Comment #133
hmdnawaz commentedThere is no way to override or add new variables to the template.
I have tried with
mytheme_preprocess_maintenance_page(&$variables)but it is not picked up.It is still taking the variable values from the function
_drupal_log_errorHere when I add my custom variable like this:
and print it in the template as
{{ custom_var }}it is working, but I thinkmytheme_preprocess_maintenance_page(&$variables)is not a preprocess function for this offline template.Is there any other preprocess function available for this template? How can I override the existing variables of the template and add new variables?
Comment #135
nigelcunningham commentedI would suggest that the test in FinalExceptionSubscriber not display the offline message if the error level is verbose. (Change the content type test to:
I've adjusted the patch from 121 in this attachment.
Comment #136
drdam commented#135 works against 9.4.x and 9.5.x
Comment #138
dariemlazaroThis should be taken more seriously as a matter of system reliability in the event of errors. After applying patch #135 in core 9.4.8 and copying the
maintenance-page--offline.html.twigtemplate to my theme templates directory (themes/custom/mytheme/templates/maintenance-page--offline.html.twig), the template renders correctly but it is not possible to modify any of its variables from my .theme file, it does not receive any CSS, nor JS, nor does it accept any preprocessing.Analyzing the patch and trying to add new variables from errors.inc these worked in the template. To make the solution as generic as possible I made the following changes to errors.inc on line 277:
And this function at the end of the file:
Then modify the maintenance-page--offline.html.twig template:
In this template I also decided to add animations to make it not so flat.
Then in the public files directory (/sites/default/files) add a favicon.svg, a logo.svg and a maintenance folder to put CSS, JS and images files.
Optional (for animations): place the AOS library in an aos folder inside maintenance.
This is my CSS in maintenance.css, note that the '@import' is for loading the aos library from the CSS itself:
This is my JS in maintenance.js, the function to concatenate the JS fails to load because of some access restriction, so I manually concatenated jQuery and the AOS library and then put my custom code:
After all this "superhuman" effort I managed to create an offline maintenance page with a similar style and behavior (animations) to the online maintenance page (just change the texts). Of this last one it would be necessary a way to access to those variables of the site and to show them in the template so that it is not necessary to put the plain text.
Please someone review these modifications to see what can be improved and please update the patch with these changes that are a temporary solution to this problem, it is not the best but it solves. I don't know how to update the patch on my own or make patches. Thanks in advance and I hope this solution will be helpful.
Translated with www.DeepL.com/Translator (free version)
Comment #139
newaytech commentedThanks for the patch #151 - this applied for me on Drupal 9.5 - and I was able to change the offline page within a minimal theme I have created just for offline pages across all my multisites.
The issues I cannot fathom - is how to elegantly alter the response code of the error page. If we have a database issue - I need a 504 - such that my upstream proxy serves an interim cached site page - any thoughts around this? Previously, we could achieve that using a preprocess hook - but as we're bypassing the drupal ecosystem and going direct via twig - I can't see how to alter the response code.
Comment #141
tonytheferg commentedCan't get 135 to apply on 10.1.1 with composer.
Comment #142
jrbHere's the patch in #135 re-rolled for 10.1.
Comment #143
tonytheferg commented142 applies, but it's not picking up my maintenance-page--offline.html.twig file.
Comment #144
tonytheferg commentedAhh... I was missing this step:
Comment #145
hmdnawaz commentedRe-rolled the patch for 10.2
Comment #148
jwilson3@binoli-lalani: Please change the title of the MR back the way it was. This issue has nothing to do with fixing missing hyphens for prefixes - Words starting with "de"
The title should be:
Issue #2720109 by Spokje, kndr, sharma.amitt16, maacl, felribeiro, Neslee Canil Pinto, yogeshmpawar, quietone, zeuty, joey-santiago, Brian-C, ranjith_kumar_k_u, seppelM, jenny.cha, kiwimind, NikLP: maintenance-page--offline.html.twig is not picked up when system is offlineComment #150
adwivedi008 commentedHello @everyone
I also tried to change the title using git (by changing the commit message ), but sadly, that is not working, and I don't have access to change it directly at MR
Comment #152
brandonlira commentedHi @jwilson3,
The original merge request seemed to be abandoned and the title was still incorrect.
Since there was no update, I created a new branch using cherry-pick and opened a new MR with the correct title as suggested.
Some minor adjustments were also made to fix issues that were causing test failures.
Let me know if there's anything that needs to be changed or improved.
Comment #153
smustgrave commentedLeft comments.
Comment #154
hmdnawaz commentedpatch for 11.2 without tests
Comment #155
hmdnawaz commentedThe above patch in 154 is wrong. The correct one with tests.
Comment #156
hmdnawaz commentedComment #158
jaypan154 and 155 don't patch for Drupal 11.3 for me. How about others?
Comment #159
rkelbel48 commented#155 patch worked for me on Drupal 11.3.3, but you definitely need to make sure your maintenance-page--offline.html.twig is in your theme's template folder and not within a sub-directory. Once I applied the patch and moved it to just "templates" directory, the site picked it up as expected.
Comment #160
rkelbel48 commentedI have a functional offline maintenance page using 155, tests well. Do we need more people testing it or could we move this forward to get it merged before core updates again and we miss the opportunity to get this in. It's been a long road for this work already.
Comment #161
smustgrave commentedThe MR has numerous errors, needs a rebase, and needs a review before going to RTBC
Comment #162
mradcliffeI am removing the Novice tag from this issue because it is not as straightforward to manual test and provide a good review.
I’m using this documentation as a source: https://www.drupal.org/community/contributor-guide/task/triage-novice-is...