Problem/Motivation
Branching off of a suggestion from https://www.drupal.org/project/drupal/issues/3278493 this proposal is to update development.services.yml to include Twig debugging by default.
As it currently stands, the process for enabling Twig debugging requires the user to uncomment some settings from settings.local.php then adding in the twig debugging settings to development.services.yml. This is not a very beginner-friendly process.
example.settings.local.php is filled with helpful comments and information regarding what each option does and if it should be uncommented or changed for various purposes. In contrast, development.services.yml has very little information and requires the user to add in additional information that they would not otherwise know about. Twig debugging is one of the most important features to enable when building a theme and it makes sense that it should be enabled by default in development.services.yml or at least the settings should be in the file but commented out with an explanation about what would happen if they are uncommented.
Proposed resolution
Currently development.services.yml looks like this:
parameters:
http.response.debug_cacheability_headers: true
services:
cache.backend.null:
class: Drupal\Core\Cache\NullBackendFactory
This would update the file to look like this:
parameters:
http.response.debug_cacheability_headers: true
# Twig debugging settings for explanation of what each option does, see:
# https://www.drupal.org/docs/theming-drupal/twig-in-drupal/debugging-compiled-twig-templates#options
twig.config:
# Html comments for Twig templates: set to true to enable
debug: true
# Caching the Twig templates in the Render API:
# set to false to disable caching so a re-render happens
# every time a template is updated
cache: false
services:
cache.backend.null:
class: Drupal\Core\Cache\NullBackendFactory
Remaining tasks
Get DX feedback
User interface changes
API changes
Data model changes
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | image (7).png | 77.38 KB | libbna |
Issue fork drupal-3278887
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
vighneshh commentedComment #3
vighneshh commentedAdded a patch regarding this issue
Please review
Comment #4
vighneshh commentedThe last one failed so added this new patch
Comment #5
libbna commentedPatch #4 applied successfully. Moving the issue to RTBC.
Comment #6
libbna commentedAdding screenshot.
Comment #8
rlahoda commentedI don't know if this will work because I'm not really familiar with patches and I have never tried creating a patch for Drupal core, but I noticed a typo in my original text with an extra space before the url at the top. Here's an update to the one VIGHNESH SADAGOPAL created but I did it by directly editing the original patch. I don't know if that will cause an error since there might need to be a different hash or something. If it's not correct, I would appreciate someone creating one the correct way. Thanks for all your help!
Comment #9
WebbehRE #8, I would recommend not editing `.patch` files directly.
To add on to a patch, take a look at the interdiff documentation page on how to revise between versions: https://www.drupal.org/docs/develop/git/using-git-to-contribute-to-drupa... . For a complete summary of the process (including applying a patch. adding onto a patch, etc), please see: https://www.drupal.org/docs/develop/git/using-git-to-contribute-to-drupal
That being said, we probably should be using the GitLab fork + MR for ease-of-use and easier contributions.
Marking back to NW for the test fail in #4, which I don't think was checked (or fixed) in #8 or others.
Comment #11
rlahoda commented@Webbeh, thanks for your input about the patch files. I went ahead and used the Gitlab process you suggested and created this MR. I have it labeled as draft because I'm new to the process here for Drupal and wasn't sure if more info is needed or anything else. https://git.drupalcode.org/project/drupal/-/merge_requests/2229
Comment #12
rlahoda commentedI'm not sure how to have the tests run on the MR so I don't know how to check/fix the fail in #4. I tried marking it as "ready" to see if that would trigger any tests in Gitlab but it doesn't appear to have done anything so I'm not sure what else to do.
Comment #13
tim.plunkettThe tests ran when you marked it Ready, a slight delay maybe. All good now!
Something else went wrong in that test run, but the main failure was
Drupal\Tests\ComposerIntegrationTestwhich compares several specific files after a composer installation.The key is to also change
assets/scaffold/files/development.services.ymlso that they match.Comment #14
rlahoda commentedThanks @tim.plunkett! I updated assets/scaffold/files/development.services.yml and pushed to the MR, how do I tell it to re-test? and were does it list the results of the tests? Maybe I'm just missing it but I don't see it listed in gitlab or on here.
Comment #15
rlahoda commentedIf I'm reading the status page correctly, it looks like the latest push passed? https://dispatcher.drupalci.org/job/drupal_patches/127439/ So I'm not sure what to do next.
Comment #16
rlahoda commentedSince it looks like the latest build passed all the tests, I'm updating the status to needs review.
Comment #18
spokjeBack to NR. Failure was for patch file, and we're now using the MR. Also hidden patch #5 to make that a bit more clear.
Comment #19
mglamanMarking NW on this comment in
default.services.ymlShould we be setting
cache: falseoverauto_reload: true? I normally do what is in the proposal. But maybe it's better to do what the docs actually recommend.Comment #20
rlahoda commentedUpdating to Needs Review after updating and tests passed
Comment #21
mherchelAssigning to myself to review.
Comment #22
antoniya commentedJust a few typo fixes in the IS.
I think this would be a nice improvement for DX. God knows how many times I've forgotten to exclude development.services.yml from scaffolding so that its contents got reset by drupal/core-composer-scaffold and I had to enable twig debug again.
Should the include of development.services.yml in 'container_yamls' in example.settings.local.php then be commented out by default? To prevent unexperienced users from enabling twig debug on their live sites? Or alternatively we could leave it as is but add a warning that production sites should comment out the line?
Comment #23
smustgrave commentedThis issue is being reviewed by the kind folks in Slack, #need-reveiw-queue. We are working to keep the size of Needs Review queue [2700+ issues] to around 200
Believe this may have missed the boat for 10.0 but maybe could land in 10.1
Moving to NW so the MR can be updated for 10.1
Comment #24
jwilson3The approach on this issue seems to duplicate #3272587: Enable theme debugging by default in development.services.yml which was already closed as a duplicate of #2839709. Please read on:
Per @Cottser circa 2017 in #2839709-6: Make Debugging Twig easier:
On #2839709: Make Debugging Twig easier we took another approach, to add a separate twig-debug.services.yml because:
Have these questions been addressed? Can they? If not, I'm inclined to close this in favor of consolidating effort around #2839709: Make Debugging Twig easier and its waaaay more complicated successor #3278493: Make it easier for theme builders to enable Twig debugging and disable render cache.
The issue summary on this issue says:
The approach on #2839709: Make Debugging Twig easier would have you literally uncomment a single line of code in settings.local.php to enable twig debugging, and doesnt suffer from any of the 3 drawbacks presented above. I would humbly ask for folks invested here to look there and see if there are any flaws in our thinking.
If you insist on continuing here, then at the very least I would have to insist on updating the code to add link to the Meta issue for known issues with enabling twig debug by default here: #2914733: [META] twig debug can break parts of site. Adding such a link is not going to help too much, because people will not know that Twig debugging is the root cause of many of these issues, adding to further confusion between differences on LOCAL / PROD.
Comment #25
jwilson3Comment #26
joelpittetClosing this as a duplicate of #2839709: Make Debugging Twig easier as well, thanks for outlining all the points @jwilson3 in comment #24 #3278887-24: Update development.services.yml to include twig debug by default
Cottser is of course right :D there are subtle side-effects of having this on that should be made clear. If you have very granular templates where it's rendered inside a tag, the HTML comments generated by twig_debug can break the layout, and some other subtle things around whitespace issues and HTML. Those are the side-effects we saw while adding twig to core.
Let's focus on the other issue and thanks for helping make the DX better!