Problem/Motivation

Seeing changes in your Twig templates is difficult without specific Drupal knowledge.

Here is my go to configuration when theme building in Drupal:

Turn on Twig debug in sites/default/services.yml:

  twig.config:
    debug: true
    auto_reload: null
    cache: true

Disable page, dynamic_page, render cache so I get fresh data as I edit Twig templates:

$settings['container_yamls'][] = DRUPAL_ROOT . '/sites/development.services.yml';
$settings['cache']['bins']['render'] = 'cache.backend.null';
$settings['cache']['bins']['page'] = 'cache.backend.null';
$settings['cache']['bins']['dynamic_page_cache'] = 'cache.backend.null';

Rebuild Drupal cache. Launch Laravel Mix with Browsersync, and go!

The problem is that this is fairly clunky and very backend orientated.

Proposed resolution

A walkthrough on the new form is below. This was approved by UX maintainer @ckrina (any changes will be captured in followup issues).

Additional notes

When enabled, this will output an error on the status report page:

Remaining tasks

Follow-up issues

#3278887: Update development.services.yml to include twig debug by default

A new “Development settings” page at /admin/config/development/settings that contains Twig development settings, as well as the ability to disable various caches. The settings are stored within the state table (as opposed to configuration), so the settings cannot be accidentally committed and uploaded to production environments.

CommentFileSizeAuthor
#121 interdiff.txt1.34 KBlauriii
#121 3278493-121.patch16.07 KBlauriii
#117 interdiff-111-117.txt738 bytesmherchel
#117 3278493-117.patch15.81 KBmherchel
#111 interdiff-3278493-104-111.txt2.89 KBmglaman
#111 3278493-111.patch15.81 KBmglaman
#104 interdiff-3278493-100-104.txt4.88 KBmglaman
#104 3278493-104.patch14.63 KBmglaman
#102 Status_report___Drupal.png67.87 KBmherchel
#102 walkthrough.gif459.2 KBmherchel
#100 3278493-100.patch15.2 KBmglaman
#99 3278493.95_99.interdiff.txt485 bytesdww
#99 3278493-99.just-95-fix-phpcs.will-fail.patch15.13 KBdww
#98 3278493.97_98.interdiff.txt485 bytesdww
#98 3278493-98.combined-with-3358048.patch16.58 KBdww
#97 3278493-97.combined-with-3358048.patch16.86 KBdww
#95 3278493-95.patch15.45 KBmglaman
#95 interdiff-3278493-90-95.txt6.27 KBmglaman
#90 interdiff-89-90.txt705 bytesmherchel
#90 3278493-90.patch14.55 KBmherchel
#89 interdiff-87-89.txt1.06 KBmherchel
#89 3278493-89.patch14.45 KBmherchel
#87 interdiff-3278493-85-87.txt26.41 KBmglaman
#87 3278493-87.patch14.15 KBmglaman
#85 interdiff-3278493-82-85.txt25.97 KBmglaman
#85 3278493-85.patch14.51 KBmglaman
#83 image.png75.95 KBmherchel
#83 Screenshot_5_3_23__1_02_PM.png11.8 KBmherchel
#82 3278493-82.patch18.84 KBbenjifisher
#82 interdiff-3278493-81-82.txt1.05 KBbenjifisher
#81 interdiff-79-81.patch886 bytesmherchel
#81 3278493-81.patch18.98 KBmherchel
#79 interdiff-73-76.txt6.76 KBmherchel
#79 3278493-76.patch18.98 KBmherchel
#73 3278493-73.patch18.04 KBmglaman
#66 3278493-66.patch13.57 KBmglaman
#64 3278493-63.patch13.28 KBmglaman
#59 3278493-59.patch12.55 KBmglaman
#59 interdiff-3278493-58-59.txt19.81 KBmglaman
#58 3278493-57.patch14.72 KBmherchel
#43 Performance___Drupal.png79.87 KBmherchel
#43 Configuration___Drupal.png119.86 KBmherchel
#34 Screen Shot 2022-09-22 at 2.57.22 PM.png767.06 KBandy-blum
#34 Screen Shot 2022-09-22 at 2.52.00 PM.png1.97 MBandy-blum
#34 Screen Shot 2022-09-22 at 2.50.48 PM.png975.91 KBandy-blum
#34 Screen Shot 2022-09-22 at 2.50.31 PM.png1.88 MBandy-blum
#25 3278493-updating-CoreServiceProvider-theming-debug-test-v2.patch2.66 KBpurencool
#25 3278493-updating-ThemeAdminForm-theming-debug-test-v2.patch1.79 KBpurencool
#24 3278493-updating-CoreServiceProvider-theming-debug-test.patch2.65 KBpurencool
#24 Screen Shot 2022-07-22 at 4.46.19 PM.png55.97 KBpurencool
#24 3278493-updating-ThemeAdminForm-theming-debug-test.patch1.79 KBpurencool

Issue fork drupal-3278493

Command icon 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

mglaman created an issue. See original summary.

mglaman’s picture

Issue summary: View changes
jeroent’s picture

I think this issue is very similar to #1969278: UI for enabling twig debugging

mglaman’s picture

It is similar, but adds scope to disabling caches, because Twig debug is kind of useless without that.

Per https://twitter.com/plopesc/status/1521720652457205760?t=vfyE2hfnG0QIBjq... from plopesc, we could give this a UI which reads from the state key value storage.

mherchel’s picture

Huge +1 on this:

+1

I actually talked to @lauriii about this, and he seemed really on board with this idea too!

I also like the idea of having a UI to turn on and turn off.

Let me know what I can do to help!

mglaman’s picture

Here is my thought process:

* Add a checkbox to "Performance" or something under theme settings. This sets a value in the `state` key value store.
* Add a new ThemeDebugPass compiler pass in \Drupal\Core\CoreServiceProvider
* ThemeDebugPass checks if `state` is viable (install)
* If `theme_debug` is set, ThemeDebugPass sets twig.config.debug to true, registers cache.backend.null and sets it for page, dynamic_page, render cache bins
* Add something to the status report page warning site is in theme debug mode. Ideally it'd be a badge in the admin toolbar as well.

This shouldn't cause any conflict with backend devs modifying services.yml or settings.php, since they probably won't click the UI button.

The only "problem" is there isn't a code based way to trigger this setup. You have to click something in the UI. So it might be nice to have a settings.php setting AND state value.

tim.plunkett’s picture

This isn't directly accomplished now by using sites/example.settings.local.php, but there's overlap. Not suggesting we expand scope here, but perhaps that file will need to be adjusted to acknowledge this new feature.

andy-blum’s picture

Would it be a bad practice/poor DX to have multiple avenues of activation? While a simple checkbox in performance would be great, as would a one-liner in settings.php, I could also see agencies liking the idea of an environment variable so that dev servers could just have all sites in dev mode all the time.

Also, would having the setting in config have any kind of tangible performance hit versus settings.php/environment variable?

mherchel’s picture

Would it be a bad practice/poor DX to have multiple avenues of activation?

Yeah, if we were starting from scratch. And this is definitely something we need to consider for the DX.

However, keeping the activation of the debugging/cache as it is, is very bad DX. I'm not sure we can or should remove the old method.

mglaman’s picture

Also, would having the setting in config have any kind of tangible performance hit versus settings.php/environment variable?

Config has the danger of being exported.

Would it be a bad practice/poor DX to have multiple avenues of activation?

As @mherchel said, yes if it was fresh. However, this helps combine a poor DX. Do themers, right now, know to disable render cache to avoid cache rebuilds?

Drupal often has a UI option with code option. This new "switch" just combines something which exists in service definition and another in settings cache bin overrides. I don't think the existing options need to be changed. I think we just need a way to do both at the same time fairly easily.

Not suggesting we expand scope here, but perhaps that file will need to be adjusted to acknowledge this new feature.

Correct, it's half documented in the example.settings.local.php where it adds the development services definition and commented out lines for render caches. However it requires reading _a lot_ to know. And it's in two places

* copy default.services.yml to services.yml, modify a boolean in twig.config.debug
* copy example.settings.local.php, uncomment 3 lines

IDEALLY we could set the environment for the DrupalKernel to `dev` and it'll set this up automatically. But Drupal isn't there, yet. And there are reasons to use caching locally for debugging cache metadata.

rlahoda’s picture

A UI switch would be ideal for this, especially if it's tied to an environmental variable or something that would keep it from activating on a production environment. It would make the experience much easier for someone unfamiliar with Drupal who's trying to get started and be much easier for everyone else to do as part of the process.

Another, less friendly option, would be to just have devlopment.services.yml updated so that it has the twig debug settings already in there. This would at least mean that the option would already be there, similar to how example.settings.local.php has everything needed in there already it's just up to the user to uncomment what they want. Doing that would at least mean that the user wouldn't have to go find what the options they need to add in.

Generally, though, this seems like the kind of functionality that should be a single-step option to enable. The current process is definitely not beginner-friendly and if something is missed or incorrectly entered, the user can get pretty frustrated trying to figure out what was missed. I know this from my experience first learning Drupal right when D8 was coming out.

mglaman’s picture

Assigned: Unassigned » mglaman

Another, less friendly option, would be to just have devlopment.services.yml updated so that it has the twig debug settings already in there.

+1 that would be nice and we should open a follow up ticket. Having specific control of Twig via a development services file vs a "all the things" is still a use case in my opinion.

---

Assigning to myself. We've had quite a bit of feedback and I'll work on an initial MR/patch from my proposal in #6

btully’s picture

Thank you for raising this @mglaman! This would be a huge improvement in DX. I'd go so far as to say that Drupal should give a warning when it recognizes that Twig debug is enabled but cache (page cache/dynamic page cache/render) is not disabled! I've been burned by that more times than I'd like to admit ;)

rlahoda’s picture

Assigned: mglaman » Unassigned

+1 that would be nice and we should open a follow up ticket.

@mglaman Based on your suggestion I created that issue: https://www.drupal.org/project/drupal/issues/3278887

Webbeh’s picture

Webbeh’s picture

Issue summary: View changes
mglaman’s picture

Assigned: Unassigned » mglaman

Working on this

mglaman’s picture

Assigned: mglaman » Unassigned
Status: Active » Needs work

I have a WIP test. It might be impossible with a Kernel test. Kernel tests replace the cache_factory with Drupal\Core\Cache\MemoryBackendFactory which makes it impossible to test settings in CacheFactory.

Copy of test I was hacking together:

<?php

namespace Drupal\KernelTests\Core\Theme;

use Drupal\Core\Cache\MemoryBackendFactory;
use Drupal\Core\Cache\NullBackendFactory;
use Drupal\Core\Site\Settings;
use Drupal\KernelTests\KernelTestBase;
use Symfony\Component\DependencyInjection\Reference;

/**
 * Tests theme_debug functionality.
 *
 * @group Theme
 */
class ThemeDebugTest extends KernelTestBase {

  public function testRenderCacheBackend(): void {
    $this->assertCacheBinFactory('render', MemoryBackendFactory::class);
    $this->toggleThemeDebug();
    $this->assertCacheBinFactory('render', NullBackendFactory::class);
  }

  private function toggleThemeDebug(): void {
    $this->setSetting('theme_debug', !Settings::get('theme_debug', FALSE));
    $this->container->get('kernel')->rebuildContainer();
  }

  /**
   * @phpstan-param class-string $expected
   */
  private function assertCacheBinFactory(string $bin, string $expected): void {
    self::assertTrue($this->container->hasDefinition("cache.$bin"));
    $factory = $this->container->getDefinition("cache.$bin")->getFactory();
    self::assertIsArray($factory);
    $reference = $factory[0];
    self::assertInstanceOf(Reference::class, $reference);
    self::assertInstanceOf(
      $expected,
      $this->container->get($reference)
    );
  }

}

Unassigning for now.

andy-blum’s picture

Would it be possible to also remove development.services.yml from Drupal's default scaffolding?

The issue #3278887: Update development.services.yml to include twig debug by default would help a lot of people, but the problem remains that any development service customizations will be overwritten with every composer require/update/install. If a site has made a customization to the CORS config, for example, they'll also need to make sure they disable the scaffolding for that file or it'll soon be reset to its default state.

We don't overwrite settings.php or settings.local.php, so why should we be overwriting development.services.yml?

jwilson3’s picture

Is this a duplicate of #2839709: Make Debugging Twig easier ?

The approach there lets us get the benefits of turning on twig auto_reload for all developers in development.services.yml, while leaving Twig debug off by default, and enabling it via a separate services file (by uncommenting a line of code in settings.local.php). The reason we took this approach is because twig debug can break some websites, whereas auto_reload has no drawbacks.

jwilson3’s picture

Component: other » theme system
adamps’s picture

Thanks @jwilson3. The problems with twig debug are listed in #2914733: [META] twig debug can break parts of site.

purencool’s picture

I have created two test patches that if theme_debug is set not on the file system the configuration that is managed by core/modules/system/src/Form/ThemeAdminForm.php is used. The image below gets the twig.debug.debug_setting configuration created by the form through the Drupal UI and then sets the twig.config debug to true or false.

purencool’s picture

Updated to the two patches so they will pass the automated testing.

mherchel’s picture

Here's a contrib module that seems to add the same functionality https://www.drupal.org/project/twig_debugger

neclimdul’s picture

mostly though it works by writing default.services.yml which might actually just destroy your site :-/

neslee canil pinto’s picture

@neclimdul Twig debugger module as got a config form where we can enable twig debugging by ticking the checkbox and saving the form, where it will create a new file called services.yml and copy default.services.yml's file into it.

And in services.yml for now we have just manually done debug: true, auto_reload: true, cache: false, but we can also provide users expose these 3 keys by giving users to toggle these 3 keys in form, I have thought about it and will be pushing it in next release. Not sure if this is the right way to play with drupal sites folders and files.

ghost of drupal past’s picture

This is absolutely lovely but have we considered storing this in session instead of config? Would need some thought for anonymous but I wanted to float the idea.

rabbitlair made their first commit to this issue’s fork.

rabbitlair’s picture

I created a new MR, based on previous work from mglaman, implementing the following approach:

- A checkbox to enable and disable the theme debug mode is added to `/admin/appearance/settings`.
- The checkbox value is stored in Drupal's state, so no changes are generated when configuration is exported.
- In form submit, when the value is changed only, caches are cleared for debug mode to be enabled/disabled immediately.
- The value stored in Drupal's state can be overridden from settings.php file by setting a boolean variable named $settings['theme_debug']. When this variable is set, the checkbox is disabled to avoid confusion about what the expected behavior is.
- Added the test from comment #19 with some minor changes.
- A warning is displayed in `/admin/reports/status` when the theme debug mode is enabled.

andy-blum’s picture

Did some in-person review at DrupalCon Prague and there are a couple issues:

  1. The form field gets added to the global theme settings as well as all installed themes' settings pages. This is not desirable. I'm of the opinion that this checkbox should live in the same form as the caching & aggregation settings as mglaman pointed out in #6
  2. The checkbox doesn't run on my machine - @alexpott helped debug this and points out that we need to move the functionality added in the coreserviceprovider to the alter function to have it run as late as possible.
andy-blum’s picture

Following 8a5c49fb this functionality works beautifully

  1. Start with a site not in debug mode
  2. Check the box
  3. Save the form
  4. Wait for page reload
  5. profit.

I don't have the skillset to do an analytical code review, but I can say with certainty that frontend devs around the world are going to LOVE this.

rabbitlair’s picture

Thank you @andy-blum and @alexpott for your help! I have added a new commit to move the checkbox from the Theme settings form to the Performance form.

rabbitlair’s picture

Status: Needs work » Needs review

.

adamps’s picture

Great that this issue is active and making progress. I have commented already on #2839709: Make Debugging Twig easier. This issue is seemingly taking over, with the advantage of adding a GUI so I'll make the same comments here.

There are 3 relevant Twig settings:

  1. auto_reload: always useful in development
  2. debug: often useful, but causes major bugs on some sites, see #2914733: [META] twig debug can break parts of site
  3. cache: should always be enabled even in development. This setting is already enabled by default so no changes are needed.

I suggest we could usefully use the same approach adopted in the other issue, and allow twig:debug to be controlled separately. So there would be a checkbox "enable debug", and if this is set, another checkbox "twig debug", which defaults to enabled, but can be disabled if needed. There can be a warning about the possible problems in the field description.

What do people think?

jwilson3’s picture

Personally, I don't think a GUI is needed to change one single config. It should be a one-line code change in settings.local.php (hence the other issue), but I'm biased towards low-code solutions and small core.

Even Matt in the OP on this issue mentioned the Proposed Solution:

I think it belongs in settings.php since it's easier to have local overrides there. Drupal doesn't have out-of-the-box local site service definitions.

At the very least the approach on the PR on this issue needs an IS update.

mherchel’s picture

Personally, I don't think a GUI is needed to change one single config.

I hear what you're saying, and I'm assuming this will be changeable via the settings.php, but IMO one of the primary purposes of this is to make it easier for new-to-drupal front-enders to get up and running. Even a making a change to settings.php can sometimes be difficult.

mherchel’s picture

Status: Needs review » Needs work

@rabbitlair and @mglaman - thank you so much for working on this! This is really going to smooth the process for front-enders starting out w Drupal.

I'm setting this back to Needs Work because it's consistently failing tests (I re-ran them and they still failed). The failures seem like they should be unrelated, but either way we need to investigate.

I'd also like to spend a bit of time bikeshedding on the verbiage.

  1. The checkbox label is currently Theme debug mode - This setting affects more items than just theming, right? Maybe we should call it "Development mode" or something?
  2. The description is currently Enable theme debug mode. This option will turn Twig debug mode on, and set Null cache backend for page, dynamic_page, and render cache bins. Cache will be rebuilt after changing this setting.. I personally think we can skip saying exactly what caches are disabled, and maybe something along the line of "You can see changes in your templates without rebuilding cache", and it will show template suggestions within the HTML comments. We also need a big ol' warning that says, "DO NOT USE ON PRODUCTION!" or something :)

Thoughts on all of this? I'm really excited about this. Thank you everyone for working on it!

andy-blum’s picture

@adamPS brings up a good point:

There are 3 relevant Twig settings:

  1. auto_reload: always useful in development
  2. debug: often useful, but causes major bugs on some sites, see #2914733: [META] twig debug can break parts of site
  3. cache: should always be enabled even in development. This setting is already enabled by default so no changes are needed.

We're currently setting all three of these values with a single checkbox as well as nullifying a bunch of caches. I wonder if a new fieldset with multiple checkboxes would be good to have more granular control?

Also, to @mglaman and @jwilson3's point:

I think it belongs in settings.php since it's easier to have local overrides there.

@rabbitlairs solution allows settings.php overrides and avoids using config to set the values. So there's virtually no risk of accidentally exporting the values, and a production site can always set the values how they want them in settings.php to prevent accidental usage there.

bronzehedwick’s picture

First, this is a great option that will certainly make my life easier. I'd like to add my voice to having the option exposed in all 3 places: settings.php, in the performance admin ui, and as an environment variable. Each serves the needs of a different user archetype.

mherchel’s picture

Issue summary: View changes
StatusFileSize
new119.86 KB
new79.87 KB

I reached out to @lauriii and @mglaman on this to brainstorm. I’m updating the issue summary with a solution that we all believe works really well.

mglaman’s picture

🥳 I love it.

adamps’s picture

Great thanks it's a good start, but misses some important points.

1) This solution doesn't cover comment #37. I'll post that again to save people searching back:

There are 3 relevant Twig settings:

  1. auto_reload: always useful in development
  2. debug: often useful, but causes major bugs on some sites, see #2914733: [META] twig debug can break parts of site
  3. cache: should always be enabled even in development. This setting is already enabled by default so no changes are needed.

I suggest we create two separate settings:

  1. Twig debugging: enables auto loading of changed templates and the dump() function.
  2. Template debug comments (only available when the first one is enabled, defaults to enabled). Needs a warning that it can breaks some parts of the site.

2) It doesn't cover comment #42 and various others also to allow control from settings.php.

3) The description in the IS of the checkbox seems wrong, see documentation).

Set this option to false to disable Twig template compilation. However, this is not recommended; not even in the dev environment, because the auto_reload option ensures that cached templates which have changed get compiled again.

The setting should enable auto_load not disable cache. I don't see any need for a relationship to the "Disable all caches" setting.

mherchel’s picture

@AdamPS The thought process that was discussed with @lauriii is that the use-case of enabling only one at a time is an extreme edge-case (in fact, in all my years, I've yet to run into it). In the event that someone does need to enable only one or the other, they can do so using the current means (services.yml + settings.php)

It doesn't cover comment #42 and various others also to allow control from settings.php

The new states would still be configurable via settings.php.

The description in the IS of the checkbox seems wrong, see documentation).

Which checkbox? Caching needs to be disabled for changes in Twig templates to be immediately viewable.

adamps’s picture

Thanks for the reply.

@AdamPS The thought process that was discussed with @lauriii is that the use-case of enabling only one at a time is an extreme edge-case

Well we could try to measure this quantitatively:

I have hit it on several sites. At least one other commenter has made the same point (so that makes 2 out of the 16 people commenting, more than 10%). If we make a GUI setting that makes it easy for people to enable twig.debug then it's likely a lot more people will hit it, and it's pretty hard to debug when it happens. The "current means" to workaround you refer to are not easy, hence this issue.

What is the big problem with splitting this out in the end? The current solution bundles 3 settings that are clearly distinct in the TWIG world, and it makes for a long description to explain because the effects are quite distinct from each other. Would it be such a bad thing to split into 2 separate settings each with a shorter description?

The new states would still be configurable via settings.php.

Great. Please this could be clarified in the IS with an example?

Which checkbox? Caching needs to be disabled for changes in Twig templates to be immediately viewable.

Currently the checkbox is called "Enable Twig Debug Mode".
No that's my point - please read the docs I linked to😃. auto_reload needs to be enabled to have this effect.

mherchel’s picture

Issue summary: View changes

What is the big problem with splitting this out in the end? The current solution bundles 3 settings that are clearly distinct in the TWIG world, and it makes for a long description to explain because the effects are quite distinct from each other. Would it be such a bad thing to split into 2 separate settings each with a shorter description?

That's a good point. The thought is to provide a simplified UI.

Great. Please this could be clarified in the IS with an example?

I'll clarify that this needs to be available within settings.php, but we'll leave the actual code to whoever is developing this.

No that's my point - please read the docs I linked to😃. auto_reload needs to be enabled to have this effect.

In my testing and conversations, I'm not sure this is correct. If debug is enabled, the other two settings do not have an effect.

mherchel’s picture

I'll reach out to @lauriii to make a decision on the points that you've discussed. I'd like to keep momentum on this issue.

adamps’s picture

Thanks @mherchel

In my testing and conversations, I'm not sure this is correct. If debug is enabled, the other two settings do not have an effect.

My recollection is that if debug is enabled then auto_reload is automatically enabled. Disabling cache is clearly documented as not recommended, so presumably we shouldn't do that.

However, this is not recommended; not even in the dev environment, because the auto_reload option ensures that cached templates which have changed get compiled again.

lauriii’s picture

I think it makes sense to try to cater to #2914733: [META] twig debug can break parts of site here even though it doesn't seem like something every user would have to run into. It could even be helpful to provide an explanation in the UI that the Twig Debug mode modifies the HTML markup and may lead into different behavior from production.

I like the simplicity of a simple checkbox, but I do believe we could make the UI with two checkboxes apprehensible as well. We could potentially visualize some of this as well by hiding the auto reload checkbox when the full "Twig debug" mode is turned on.

lugir’s picture

Mark

rabbitlair’s picture

I implemented some changes to the open MR.

A new form named "Developer settings" has been added, with its own route and menu item. It contains a checkbox, "Enable Twig debug mode", which enables the Twig "debug" flag, and two other conditional checkboxes. These are to handle Twig's "autoload" and cache disabling. The one disabling cache disables both Twig cache flag and the Drupal's page, render and dynamic page caches.

The three options can also be overridden from settings file. Please, let me know if this implementation works better!

dan_metille’s picture

Coming here to find a way to disable auto_reload, which seems to be automatic while debug is set to 'true'.
I understand that in most case it is useful, but from a theming side it is NOT ALWAYS the case and I would like to have the option to disable it. (If there is already a way, could someone please let me know). In case if we are using Vite.js to compile the theme, auto_reload is unnecessary and time consuming.

star-szr’s picture

@sahaj you can set debug to true and auto_reload to false if you want debug but not auto_reload.

The behaviour is that if auto_reload is not specified, then it inherits the value of debug.

ressa’s picture

Great work, this will be a nice improvement. Could the same be done for core and module development, so that all caches can eventually be easily disabled, via the GUI or running a single command such as drush cache:disable? #3342678: Easy way to bypass caching and aggregation with Drush or settings.php.

mglaman’s picture

Version: 10.0.x-dev » 10.1.x-dev

Bumping the version to 10.1.x

mherchel’s picture

Issue tags: +MidCamp2023
StatusFileSize
new14.72 KB

Re-rolled the MR and created a patch (since MR is against 10.0.x and Zequi is probably sleeping)

mglaman’s picture

Status: Needs work » Needs review
StatusFileSize
new19.81 KB
new12.55 KB

Reworked the patch. Moved settings to Performance from Developer settings. Streamlined the options a little bit. Removed anything involving settings.php overrides to simplify the logic. The settings.php work in the existing patch is already possible via services.yml, this issue should focus on a UI for those values.

mglaman’s picture

Assigned: Unassigned » mglaman
Status: Needs review » Needs work

I'm going to revise #59. There's no test coverage and I think empty values should be deleted from state and not saved as false.

adamps’s picture

Great to see this moving forward thanks everyone. The issue summary seems to be getting increasingly left behind.

1)

Moved settings to Performance from Developer settings.

I can see your point, as previously there was "Admin > Config > Development > Developer Settings" - and what's the difference between development settings and developer settings😃.

On the other hand we now seem to have "Admin > Config > Development > Performance" and then a details box titled "Developer settings", which still doesn't seem quite right. How about reorganising the Performance page something like this:

  • Rename "Caching" to "Web Caching"
  • New section "Internal Caching" or "Cache Bins" (or whatever the right name is). Module caches could later be added here as per #56
  • New section "Twig" containing the 3 checkboxes

2) Two of your four settings are "disable XXX" rather than "enable XXX" - potentially this negation is a confusing UI??

3) It would be great to have warnings in the form UI for the two settings that have potential disadvantages:
twig_debug: This modifies the HTML markup and may lead into different behavior from production, even causing bugs.
cache: This is recommended; even in the dev environment, because the auto_reload option ensures that cached templates which have changed get compiled again.

4) The patch seems to save the new values to state rather than config, which seems unusual and potentially confusing. I understand that the values are likely to be different on dev vs production. However that's also true for many of the other development settings. What is the advantage to this approach?

5) The code seems to invalidate the container if any value is enabled. Shouldn't this be if any value has changed?

mglaman’s picture

I'll reply to #61 in full later, but

4) The patch seems to save the new values to state rather than config, which seems unusual and potentially confusing. I understand that the values are likely to be different on dev vs production. However that's also true for many of the other development settings. What is the advantage to this approach?

This shouldn't be a configuration that can be persisted. It should be something specific to that environment, which is what the state key value store is for.

5) The code seems to invalidate the container if any value is enabled. Shouldn't this be if any value has changed?

This is why it needs test. It should be invalidating if it's ever changed but there may be edge cases.

Also: wording. I avoided trying to make it perfect because the issue comments will provide the bikeshedding for best words.

mglaman’s picture

Status: Needs work » Needs review

New patch
- fixed twig_autoreload to twig_auto_reload for cspell
- improved UX (auto-check sub-checkboxes if nothing is enabled) and values bug
- container invalidation anytime twig dev mode values change

3) It would be great to have warnings in the form UI for the two settings that have potential disadvantages:

I think it should link to official docs, because they'll stay up to date. @mherchel informed me about twig debug adding HTML comments which breaks RSS feeds. So there are edge cases and this is best handled in guides.

All wording and variable names are up for discussion, just getting work up so we can review.

mglaman’s picture

StatusFileSize
new13.28 KB

Forgot the patch 🙈

adamps’s picture

Thanks for the responses @mglaman

I think it should link to official docs, because they'll stay up to date

Great - the wording was from the docs anyway

@mherchel informed me about twig debug adding HTML comments which breaks RSS feeds. So there are edge cases and this is best handled in guides.

It's funny how many people who haven't hit this themselves say that it's an edge case😃. It's not only RSS, please see #2914733: [META] twig debug can break parts of site (which when counting together all the child issues has more followers than this one😃).

@lauriii commented in #51

It could even be helpful to provide an explanation in the UI that the Twig Debug mode modifies the HTML markup and may lead into different behavior from production.

It can save people some trouble so I wonder is there any significant disadvantage???

mglaman’s picture

StatusFileSize
new13.57 KB

New patch: fixes phpcs, and container invalidation when root twig development mode toggle used

Status: Needs review » Needs work

The last submitted patch, 66: 3278493-66.patch, failed testing. View results

mherchel credited mndonx.

mherchel’s picture

Did some hallway testing at MidCamp with front-end devs @hbrokmeier, @callinmullaney, @mndonx (crediting).

We worked on verbiage and expectations:

  • Rename the “Performance” page title (and menu entry) to “Performance and caching”
  • Change the new details label to “Theme development settings”
  • Directly within the new details element add this text:
    • These settings should only be enabled on development environments and never on production.
  • For caching description text:
    • Change label: Do not cache markup
    • Change description: Disables render cache, dynamic page cache, and page cache.
  • Use case. If we rebuild the environment, we don’t want to have to re-check this form. Can we override these settings in settings.php or have a drush command?
benjifisher’s picture

Issue tags:

I looked at this issue with M&M at MC (@mherchel and @mglaman at MidCamp 2023). What is the best way to present the options under "Twig development mode"?

The options "Enable Twig auto reload" and "Disable Twig cache" are not independent, so it does not make sense to have a checkbox for each. If I have it straight, the first option invalidates the cache if it is older than the source, and the second option completely bypasses caching. Instead of two checkboxes, I think there should be three radio buttons:

  • Normal caching
  • Cache, but recompile changed templates
  • No caching

I also reviewed the current labels and descriptions:

- [ ] Enable Twig debug mode
Enables Twig debug mode, which provides Twig's dump() function, outputs template suggestions to HTML comments, and allows to set Twig auto reload and to disable caches.
- [ ] Enable Twig auto reload
When enabled, Twig templates are recompiled when the source code changes.
- [ ] Disable Twig cache
Disables Twig template cache.

It is confusing to use "Enable" and "Disable" for checkboxes. We should avoid repeating the label in the description. We do not need a description at all if it just repeats the label. I came up with some alternative text:

- [ ] Show debug information in HTML comments
Show template suggestions in HTML comments and provide Twig's dump() function.
- [ ] Recompile changed templates
- [ ] Bypass template cache

Maybe remove "in HTML comments" from the first label.

The last option on the page is

- [ ] Disable cache bins for rendered output
Disables render cache, dynamic page cache, and page cache to bypass caching during rendering.

I suggest changing that to

- [ ] Do not cache markup
Disables render cache, dynamic page cache, and page cache.

mglaman’s picture

Issue tags:
StatusFileSize
new18.04 KB

New work-in-progress patch since I'm leaving MidCamp soon. Captures some ideas from @benjifisher where there we unify auto_reload and disable caches as a radio option. Enabling auto_reload is useless if caches are disabled because there are no compiled templates to checksum and reload.

benjifisher’s picture

I talked about this issue at MidCamp with @akalata and Jen Stein (not sure of the d.o username). We agreed that the UI should have three radio buttons, and we recommend this:

  • Cache Twig templates normally
  • Autoload Twig templates
    • Cache, but recompile changed templates
  • Do not cache templates

(That is, the middle option is the only one that needs description/help text.) Probably the middle option should be selected by default when "Twig development mode" is enabled.

mglaman’s picture

Assigned: mglaman » Unassigned

Removing myself from assignee. Not actively working on it right now, so someone else can try a reroll with with feedback included

mherchel’s picture

I talked about this issue at MidCamp with @akalata and Jen Stein (not sure of the d.o username). We agreed that the UI should have three radio buttons, and we recommend this:

The issue with this option is that it doesn't give the granularity of enabling and disabling the 3 options, as pointed out in #37 by @adamPS and +1'd by @lauriii in #51

mherchel credited akalata.

mherchel’s picture

Adding credit for @akalata's discussion with @benjifisher.

Pretty sure Jen Stein isn't on Drupal.org. I found her on MidCamp's site, but not here.

mherchel’s picture

StatusFileSize
new18.98 KB
new6.76 KB

Verbiage changes

benjifisher’s picture

I am afraid I was not clear in #74.

There are currently three checkboxes:

  • Twig debug mode
  • Twig auto reload
  • Disable Twig cache

I meant to suggest that we keep the first one and replace the other two with three radio buttons.

That reduces 4 options to 3. The one we leave out is disabling the second option and enabling the third. That combination does not make much sense: see #72. Anna, Jen, and I think this is a better UI than the suggestion at the end of #51:

We could potentially visualize some of this as well by hiding the auto reload checkbox when the full "Twig debug" mode is turned on.

mherchel’s picture

StatusFileSize
new18.98 KB
new886 bytes

Adding a missing comma

benjifisher’s picture

StatusFileSize
new1.05 KB
new18.84 KB

Let me see if I can help a little here.

If I read it correctly, PHPStan is complaining that you are telling it to ignore some lines that do not have any problems. So this patch removes the @phpstan-ignore-next-line annotations.

I am a little unsure, since core/scripts/dev/commit-code-check.sh passes locally with or without those annotations.

mherchel’s picture

StatusFileSize
new11.8 KB
new75.95 KB

Worked with @ckrina (UX Maintainer) and @mglaman on a Zoom call to nail down the user interface. For any additional improvements, please open up a followup issue.

On admin/config, this item will go directly under “Performance”

This form will go under admin/config/development/settings. The title of the page and menu item is “Development settings”

When “Twig development mode” checkbox is checked, both checkboxes within the child fieldset are checked by default.

Note that we removed the Twig auto-reload setting, as when Twig debug mode is enabled, this will automatically get enabled. This is the most common development setting for new developers. For more advanced configuration, changes can still be made in development.services.yml

Note we will open up a followup issue to provide a indication in the UI if settings are overridden.

ckrina’s picture

This is a huge improvement for front-end DX, thanks for working on this!

mglaman’s picture

Status: Needs work » Needs review
StatusFileSize
new14.51 KB
new25.97 KB
mherchel’s picture

Status: Needs review » Needs work

The form doesn't tell the user that the changes have been saved.

mglaman’s picture

Status: Needs work » Needs review
StatusFileSize
new14.15 KB
new26.41 KB

Bad interdiff. Here it is manually:

diff --git a/core/modules/system/src/Form/DevelopmentSettingsForm.php b/core/modules/system/src/Form/DevelopmentSettingsForm.php
index d8d0a51e42..49ea26126f 100644
--- a/core/modules/system/src/Form/DevelopmentSettingsForm.php
+++ b/core/modules/system/src/Form/DevelopmentSettingsForm.php
@@ -25,10 +25,12 @@ public function __construct(
    * {@inheritdoc}
    */
   public static function create(ContainerInterface $container) {
-    return new static(
+    $instance = new static(
       $container->get('state'),
       $container->get('kernel')
     );
+    $instance->setMessenger($container->get('messenger'));
+    return $instance;
   }
 
   /**
@@ -135,6 +137,8 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
     if ($invalidate_container || $disable_rendered_output_cache_bins_previous !== $disable_rendered_output_cache_bins) {
       $this->kernel->invalidateContainer();
     }
+
+    $this->messenger()->addStatus($this->t('The settings have been saved.'));
   }
 
 }
diff --git a/core/modules/system/src/Form/PerformanceForm.php b/core/modules/system/src/Form/PerformanceForm.php
index e4018e14d3..c76aaf4018 100644
--- a/core/modules/system/src/Form/PerformanceForm.php
+++ b/core/modules/system/src/Form/PerformanceForm.php
@@ -8,7 +8,6 @@
 use Drupal\Core\Config\ConfigFactoryInterface;
 use Drupal\Core\Datetime\DateFormatterInterface;
 use Drupal\Core\Form\FormStateInterface;
-use Drupal\Core\State\StateInterface;
 use Drupal\Core\Url;
 use Symfony\Component\DependencyInjection\ContainerInterface;
 
diff --git a/core/modules/system/tests/src/FunctionalJavascript/Form/DevelopmentSettingsFormTest.php b/core/modules/system/tests/src/FunctionalJavascript/Form/DevelopmentSettingsFormTest.php
index cb4e35f6e7..6f3e1d2ea2 100644
--- a/core/modules/system/tests/src/FunctionalJavascript/Form/DevelopmentSettingsFormTest.php
+++ b/core/modules/system/tests/src/FunctionalJavascript/Form/DevelopmentSettingsFormTest.php
@@ -76,12 +76,12 @@ public static function twigDevelopmentData(): array {
       'Twig development mode checked only' => [
         TRUE,
         NULL,
-        NULL
+        NULL,
       ],
       'Twig debug mode only, keep Twig cache' => [
         TRUE,
         TRUE,
-        FALSE
+        FALSE,
       ],
       'Twig debug mode off, disable Twig cache' => [
         TRUE,

mglaman’s picture

Status: Needs review » Needs work
+++ b/core/modules/system/system.install
@@ -1531,6 +1531,23 @@ function (callable $hook, string $module) use (&$module_list, $update_registry,
+  if ($phase === 'runtime') {
+    $twig_development = \Drupal::state()->getMultiple(['twig_debug', 'twig_cache_disable']);
+    if (array_reduce($twig_development, static fn (bool $toggled, ?bool $value) => $toggled ?: $value, FALSE)) {
+      $requirements['twig_debug_enabled'] = [
+        'title' => t('Twig development mode'),
+        'value' => t('Twig development mode settings are turned on. Go to @link to disable them.', [
+          '@link' => Link::createFromRoute(
+            'performance and caching settings page',
+            'system.performance_settings',
+          )->toString(),
+        ]),
+        'severity' => REQUIREMENT_WARNING,
+      ];

Wrong page! And could use individual boolean checks versus array_reduce now that only two options exist.

And cspell:

/var/www/html/core/modules/system/src/Form/DevelopmentSettingsForm.php:74:160 - Unknown word (recompiles)

mherchel’s picture

Status: Needs work » Needs review
StatusFileSize
new14.45 KB
new1.06 KB

Matt's going for a run. Updating the patch to fix 👆

mherchel’s picture

StatusFileSize
new14.55 KB
new705 bytes

No clue if this is correct. Let's find out! 🤞

Status: Needs review » Needs work

The last submitted patch, 90: 3278493-90.patch, failed testing. View results

mglaman’s picture

Assigned: Unassigned » mglaman

Debugging test failures. Also replacing usage "recompiles" to just "recompile"

mglaman’s picture

So it is due to fetching the state service during the altering of the service container.

    /** @var \Drupal\Core\State\StateInterface $state */
    $state = $container->get('state');

I should have expected that I suppose. I know this approach works with config because JSON:API Extras does it, but that's because we have BootstrapConfigStorageFactory.

Something about fetching the key-value store here breaks things. I don't know why yet.

Edit:

I think it might be because KernelTestBase switches the key-value store with a memory backend. that's why it breaks in Kernel tests but not functionally. Yep, that's it. I used Xdebug and the \Drupal\Core\KeyValueStore\MemoryStorage ends up empty at some point in time and loses its data.

When we fetch the state service and it grabs a key-value instance, I think the persist tag is bypassed, or something. When tests call \Drupal\KernelTests\KernelTestBase::enableModules it calls \Drupal\Core\DrupalKernel::updateModules which initializes the container. Then the key-value store gets reconstructed and all in-memory data is lost.

Persisting doesn't seem to work as expected here.

    $container
      ->register('keyvalue.memory', 'Drupal\Core\KeyValueStore\KeyValueMemoryFactory')
      // Must persist container rebuilds, or all data would vanish otherwise.
      ->addTag('persist');

It's related to our code in \Drupal\Core\DrupalKernel::compileContainer and \Drupal\Core\DrupalKernel::getServicesToPersist

Debugged. Our alter causes the state service to be defined before the persisted service can be re-attached

  protected function attachSynthetic(ContainerInterface $container) {
    $persist = [];
    if (isset($this->container)) {
      $persist = $this->getServicesToPersist($this->container);
    }
    $this->persistServices($container, $persist);
//..

  protected function persistServices(ContainerInterface $container, array $persist) {
    foreach ($persist as $id => $object) {
      // Do not override services already set() on the new container, for
      // example 'service_container'.
      if (!$container->initialized($id)) {
        $container->set($id, $object);
      }

We cause state to be initialized so the persisted service is not re-attached.

I tried moving to a CompilerPass and that didn't fix this problem.

mglaman’s picture

AH! So our test fails are caused by persist and #2368263: Remove the persist service tag would fix it by handling the persisted key value memory factory.

mglaman’s picture

Assigned: mglaman » Unassigned
StatusFileSize
new6.27 KB
new15.45 KB

Okay, here is an updated patch that s/recompiles/recompile and moves logic to a compiler pass outside of the service provider.

I'm going to work on a new issue that fixes the testing bug in KernelTestBase based on #2368263: Remove the persist service tag without trying to deprecated the persist tag.

mglaman’s picture

One more comment spam for the day. Linking to #3358048: Do not use persist tag for keyvalue.memory in KernelTestBase. Hopefully, that can be merged as a bug fix to unblock this issue.

dww’s picture

StatusFileSize
new16.86 KB

As a sort of test-only patch for #3358048 and to see how much closer we are, here's #95 and the MR from #3358048 applied together. Interdiff is https://git.drupalcode.org/project/drupal/-/merge_requests/3920.diff ;)

dww’s picture

StatusFileSize
new16.58 KB
new485 bytes

core/scripts/dev/commit-code-check.sh --cached now passing. 😅 Sorry for the noise.

dww’s picture

I wanted to compare #95 with #98 to prove that we should commit #3358048: Do not use persist tag for keyvalue.memory in KernelTestBase, so I queued the test run. Sadly, that failed for the unused use. So here's just #95 after running phpcbf to make core/scripts/dev/commit-code-check.sh happy. This will definitely still fail. Hopefully more like #90 than #98. 🤞

mglaman’s picture

Status: Needs work » Needs review
StatusFileSize
new15.2 KB

Here is #95 rebased off of 10.1.x, which should be the same as #99.

mglaman’s picture

Status: Needs review » Needs work
+++ b/core/modules/system/system.links.menu.yml
@@ -64,24 +64,30 @@ system.admin_config_development:
-system.site_maintenance_mode:
-  title: 'Maintenance mode'
-  parent: system.admin_config_development
-  description: 'Take the site offline for updates and other maintenance tasks.'
-  route_name: system.site_maintenance_mode
-  weight: -10
...
+system.development_settings:
+  title: Development settings
+  parent: system.admin_config_development
+  description: 'Configure theme development settings'
+  route_name: system.development_settings
+  weight: -19
...
+  weight: -10
+system.site_maintenance_mode:
+  title: 'Maintenance mode'
+  parent: system.admin_config_development
+  description: 'Take the site offline for updates and other maintenance tasks.'
+  route_name: system.site_maintenance_mode
+  weight: -5

+++ b/core/modules/system/system.routing.yml
@@ -178,7 +178,15 @@ system.performance_settings:
-    _title: 'Performance'
+    _title: 'Performance and caching'
+  requirements:
+    _permission: 'administer site configuration'
+
+system.development_settings:
+  path: '/admin/config/development/settings'
+  defaults:
+    _form: '\Drupal\system\Form\DevelopmentSettingsForm'
+    _title: 'Development settings'

Okay, I did a horrible merge here and didn't catch it.

mherchel’s picture

Issue summary: View changes
Issue tags: -Needs issue summary update
StatusFileSize
new459.2 KB
new67.87 KB

Updating issue summary.

mherchel’s picture

Issue summary: View changes
mglaman’s picture

Status: Needs work » Needs review
StatusFileSize
new14.63 KB
new4.88 KB

New patch
- fixes menu link and routing changes
- renames compiler pass from DeveloperSettingsPass to DevelopmentSettingsPass to match form name
- moves DevelopmentSettingsPass earlier before BackendCompilerPass so setting default_backend is respected

The last submitted patch, 100: 3278493-100.patch, failed testing. View results

alexpott’s picture

Status: Needs review » Needs work
+++ b/core/lib/Drupal/Core/DependencyInjection/Compiler/DevelopmentSettingsPass.php
@@ -0,0 +1,41 @@
+    /** @var \Drupal\Core\State\StateInterface $state */
+    $state = $container->get('state');

This is the reason that we needed to do #3358048: Do not use persist tag for keyvalue.memory in KernelTestBase. I think this is wrong. We can't use service in compiler passes. That's really really fraught. I think we should have left #3358048: Do not use persist tag for keyvalue.memory in KernelTestBase alone. This change will result in all KernelTests now using the database for state because it results in the instantiation of the state service prior to \Drupal\KernelTests\KernelTestBase::register() running.

We need to do something different here.

jwilson3’s picture

+++ b/core/modules/system/system.install
@@ -1532,6 +1532,24 @@ function (callable $hook, string $module) use (&$module_list, $update_registry,
+    $twig_debug = \Drupal::state()->get('twig_debug', FALSE);
+    $twig_cache_disable = \Drupal::state()->get('twig_cache_disable', FALSE);
+    if ($twig_debug || $twig_cache_disable) {
+      $requirements['twig_debug_enabled'] = [
+        'title' => t('Twig development mode'),
+        'value' => t('Twig development mode settings are turned on. Go to @link to disable them.', [

Since enabling the "Twig development mode" checkbox adds a Warning message to status report page, and "Do not cache markup" is also being introduced as a separate, top-level checkbox alongside Twig development mode, and both of these can be detrimental to website performance on production/live sites, it seems it would follow that we should also have a separate Warning message when "Do not cache markup" checkbox is enabled, right?

mglaman’s picture

This change will result in all KernelTests now using the database for state because it results in the instantiation of the state service prior to \Drupal\KernelTests\KernelTestBase::register() running.

It doesn't, this compiler pass runs after all other service providers register definitions.

What's the alternative? BootstrapConfigStorageFactory causes database calls during container compilation. I don't think Drupal core has this, but contrib does.

We need to do something different here.

It'd be a horrible idea to use config, because it could get exported and persist. Drupal core provides no alternatives or ways to prevent individual configuration objects from being exported.

Per #107: yes, you're right. It needs its own status check.

mglaman’s picture

Just to clarify the container compilation flow:

\Drupal\Core\DrupalKernel::compileContainer invokes all service providers:

    // Register application services.
    $yaml_loader = new YamlFileLoader($container);
    foreach ($this->serviceYamls['app'] as $filename) {
      $yaml_loader->load($filename);
    }
    foreach ($this->serviceProviders['app'] as $provider) {
      if ($provider instanceof ServiceProviderInterface) {
        $provider->register($container);
      }
    }
    // Register site-specific service overrides.
    foreach ($this->serviceYamls['site'] as $filename) {
      $yaml_loader->load($filename);
    }
    foreach ($this->serviceProviders['site'] as $provider) {
      if ($provider instanceof ServiceProviderInterface) {
        $provider->register($container);
      }
    }

Kernel tests register in $GLOBALS['conf']['container_service_providers'] which discoverServiceProviders adds to $this->serviceProviderClasses['site']. Kernel test registers its alias here.

The DeveloperSettingsPass runs after ModifyServiceDefinitionsPass. This compiler pass runs all service providers which implement ServiceModifierInterface.

I agree it's not the best to initialize a service during compilation. However, it is being done after all registration and alters, resulting in final processing by any remaining compiler passes.

bnjmnm’s picture

This is something I've wanted for years. The fact that it wasn't in core made me think there was some huge obstacle but this is a really solid way of doing it.

Outside of what has been reported, here's the one whole thing I noticed in my review:

+++ b/core/modules/system/system.install
@@ -1532,6 +1532,24 @@ function (callable $hook, string $module) use (&$module_list, $update_registry,
+  // Add warning when twig debug option is enabled.

Could this get test coverage? TBH not concerned about it working right in this scope, but more to ensure some later addition doesn't break it.

mglaman’s picture

Status: Needs work » Needs review
StatusFileSize
new15.81 KB
new2.89 KB

Adds status warning for disabled markup output caching. Adds tests for status report.

alexpott’s picture

@mglaman so why was the change in #3358048: Do not use persist tag for keyvalue.memory in KernelTestBase necessary - what is the root cause? My guess is that persistence is done at a different time. Ah yep \Drupal\Core\DrupalKernel::attachSynthetic() is called after everything is compiled. Should have read #93 - thanks @mglaman

I wish we'd added a bigger comment in #3358048: Do not use persist tag for keyvalue.memory in KernelTestBase :) but I can open an issue for that. I agree with @mglaman that accessing the db here through state is probably okay. We also probably should use the PassConfig::TYPE_AFTER_REMOVING etc... more in CoreServiceProvider::register() - nearly all of our stuff is being added as an optimisation pass when everything should run after the removing pass. I consider #106 resolved.

mglaman’s picture

Thanks, @alexpott! Yeah I'd love to dive into CoreServiceProvider and our CompilerPass after this, first time I really explored that area.

dww’s picture

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs Review Queue Initiative

Using a fresh install on D10.1 without a settings.local.php file and with a default development.services.yml file.

1.
Unchecked Twig development mode
Checked Do not cache markup

Went to /admin/reports/status
Verified I see "Markup caching disabled
Render cache, dynamic page cache, and page cache are bypassed. Go to development settings page to enable them."

Unchecked Do not cache markup
Verified warning in status page goes away.

2.
Before checking Twig development mode verified that debug info is not appear in markup
Checked Twig development mode
But didn't check any sub items.
Clicking save doesn't save Twig development mode
Seems expected but slightly odd. But don't think a show stopper

3.
Checked Twig development mode
Checked Twig debug mode
Did not check Disable Twig cache
Clicked save
Twig development mode is unchecked BUG
Inspect the markup and debug info is appearing.
Go to status page verify I see "Twig development mode
Twig development mode settings are turned on. Go to development settings page to disable them."

4.
Checked Twig development mode
Checked Twig debug mode
Checked Disable Twig cache
Clicked save
Twig development mode is checked
Inspect the markup and debug info is appearing

Test coverage seems good.
Other then that one small point think this is good to go.

And as posted in slack a change record should be made.

mglaman’s picture

+++ b/core/modules/system/src/Form/DevelopmentSettingsForm.php
@@ -0,0 +1,144 @@
+      '#default_value' => $twig_debug && $twig_cache_disable,

whomp whomp.

should be ||

mherchel’s picture

Status: Needs work » Needs review
StatusFileSize
new15.81 KB
new738 bytes

Good catch. Fixed in this patch.

mherchel’s picture

Change record created at https://www.drupal.org/node/3359728

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Issue I found in #115 has been addressed.

crasx’s picture

Tested this using the standard profile, with olivero:

  • Visit homepage with caching fully enabled (ie: nothing checked) - warms cache
  • Visit /admin/config/development/settings Check the do not cache markup checkbox / save
  • Update a twig template used on the homepage (I updated core/themes/olivero/templates/layout/html.html.twig)
  • View homepage, confirm new change appears with no cache clear
  • Visit /admin/config/development/settings Uncheck the do not cache markup checkbox / save
  • View homepage, note old cached version before the change appears

I would expect the new version, is that an issue?

lauriii’s picture

StatusFileSize
new16.07 KB
new1.34 KB

I gave the patch a thorough review and it looks solid. Also the UX is pretty good. I made super minor nitpick changes to the patch. Posting just to make sure custom commands pass.

I think the UI texts in the patch are fine but I'm still planning on creating a follow-up to bikeshed some of the texts.

#120: That's interesting. Maybe worth fixing in a follow-up because you'd have the same behavior right now 🤔

alexpott’s picture

Status: Reviewed & tested by the community » Fixed
Issue tags: +10.1.0 release highlights

Committed da2eaec and pushed to 10.1.x. Thanks!

  • alexpott committed da2eaec5 on 10.1.x
    Issue #3278493 by mglaman, rabbitlair, mherchel, Purencool, dww,...
alexpott’s picture

Issue summary: View changes

Adding release note.

alexpott’s picture

@crasx / #120 - that's a smart comment. I agree with @lauriii that we can address that in a follow-up.

  • alexpott committed d7663e8b on 11.x
    Issue #3278493 by mglaman, rabbitlair, mherchel, Purencool, dww,...
lauriii’s picture

wim leers’s picture

I observed this:

+++ b/core/modules/system/src/Form/DevelopmentSettingsForm.php
@@ -0,0 +1,152 @@
+      '#description' => $this->t('Disables render cache, dynamic page cache, and page cache.'),

Über nit… 🙈

s/dynamic page cache/Dynamic Page Cache/

s/page cache/Page Cache/

… because they're module names? That's also how they're capitalized in example.settings.local.php.

OTOH I like this better … because then it's consistent with "render cache". Maybe we should just lowercase them everywhere instead?

Moved to that follow-up. 👍

ckrina’s picture

Yay for getting this in! I just added #3359931: Latest/real markup should be used when caches are enabled as a followup per #120.

generalredneck’s picture

@mherchel,
Tracked down Jen Stein's username: jen.stein

mherchel’s picture

Crediting. Thanks!

ressa’s picture

Thanks everyone, this is an awesome improvement. I just used it to try the New clean_unique_id Twig filter in Drupal 10.2 (11), and it worked flawlessly.

@mherchel suggested at one point, which I agree with:

Use case. If we rebuild the environment, we don’t want to have to re-check this form. Can we override these settings in settings.php or have a drush command?

So I created #3363676: Enable Twig debugging and disable render cache via Drush and settings.php.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

chi’s picture

I'm late to the party, but don't you think that having a dedicated checkbox to expose another two checkboxes looks a bit weird from the UX perspective? That also made the logic in the form much more complex.

ressa’s picture

ressa’s picture

@keshav patel created a Drush command (theme:dev) which toggles Twig debugging, caching and aggregation, included in the latest Drush 13.6 release. See also Drupal Documentation page Disabling and debugging caching > Toggle Twig debug, caching and CSS/JS aggregation with Drush.