When working on Drupal 8 theming, it is very helpful to have Twig debug mode on. Debug mode will cause twig to emit a lot of interesting information about which template generated each part of the page. The instructions for enabling debug mode can be found within the comments of the default.services.yml file, among other sources. In short, all you need is the following in your services.yml file:
Unfortunately, there are negative implications to committing debug code into a Drupal site’s repository. On Pantheon, the repository is used as the authoritative representation of what files should be deployed to production. If you turned on debug mode via services.yml, as the documentation recommends, you would have to always remember to take it out again before publishing, or you would end up with twig debugging information on your production site—definitely not a desirable state of affairs. As a reminder to not commit to this file too lightly, Pantheon included it in the .gitignore file at the root of the repository, requiring that the git --force flag be used to add the file. The rules about what to do with the service.yml file were unclear to many users, and it was common for support to get inquiries on this subject.
Now, however, there is an easier way. As of Drupal 8.2.0, Pantheon will now load services from a secondary services file, in addition to the standard services.yml file. The name of the file varies depending on whether the environment is production or not.
|Pantheon Environment||Settings Filename|
|Production: ‘test’ or ‘live’||services.pantheon.production.yml|
|Pre-production: ‘dev’ or any ‘multidev’||services.pantheon.preproduction.yml|
These files may both be committed to the repository; only the one appropriate to the current environment will be loaded. Furthermore, the standard services.yml file has been removed from the .gitignore file, and is still loaded in all environments. If you have any configuration settings that are universally applicable, you can make them here.
Sensitive Information in a services.yml file will not be exposed through a web request; however, if there is data that needs to be in a services file, but is so sensitive that you do not want it in the repository at all, you could consider storing it in the private files directory instead. To do this, open up your sites/default/settings.php file, and find the following line:
$settings['container_yamls'] = __DIR__ . '/services.yml';
Duplicate this line, and change it so that it reads:
$settings['container_yamls'] = __DIR__ . '/files/private/services.yml';
Now settings for all environments will be loaded from this location in the private files directory. Files are shared across all Pantheon environments; if you have special needs, and want to ensure that some settings are made only on one Multidev environment, for example, then you can follow the lead of what settings.pantheon.php is doing, and use $_ENV['PANTHEON_ENVIRONMENT'] to decide which file to load.
Following these simple patterns will make managing your services file a straightforward task.