Drupal 8 FAQ: What is the correct custom theme file name (preprocess functions)?

Drupal 8 FAQ: What is the correct name for a custom drupal theme file? That is, if I want to create a preprocess_node or template_preprocess_node function, what is the name of the file that those custom Drupal 8 preprocess functions go in?

In Drupal 8 your preprocess functions go in a file in your custom theme directory that should be named to end with the .theme filename extension. So if you are creating a theme named “foo”, you should have a directory named themes/foo under your Drupal 8 installation directory, and this file will be named foo.theme.

Here’s another way to see that:

DRUPAL_8_ROOT
DRUPAL_8_ROOT/themes
DRUPAL_8_ROOT/themes/foo
DRUPAL_8_ROOT/themes/foo/foo.theme
DRUPAL_8_ROOT/themes/foo/foo.info.yml
DRUPAL_8_ROOT/themes/foo/foo.libraries.yml

While I’m in the neighborhood, this post shows the format for a Drupal 8 .theme file and preprocess function.