I tend to follow Symfony standards when it comes to helper functions. So I normally add a class under `src/Utils` for helper methods. Then I create a service for it that I can inject other services to and that itself can be injected everywhere I need it. It can also be used in procedural code (hooks) in `*.module` or `*.theme` files easily. **web/modules/custom/my_module/src/Utils/MyHelperFunctions.php** ```php namespace Drupal\my_module\Utils; /** * Class MyHelperFunctions. */ class MyHelperFunctions { /** * The Site path. * * @var string */ protected $sitePath; /** * MyHelperFunctions constructor. * * @param string $site_path * The site path. */ public function __construct($site_path) { $this->sitePath = $site_path; } /** * {@inheritdoc} */ public static function create(ContainerInterface $container) { return new static( $container->get('site.path') ); } /** * Get current multisite directory name. * * @return string * The basename of the matching multisite directory. */ public function getMultisiteAlias() { $site_path = $this->sitePath; $site = explode('/', $site_path); return $site[1]; } } ``` **web/modules/custom/my_module/my_module.services.yml** ```yaml services: my_module.helper_functions: class: Drupal\my_module\Utils\MyHelperFunctions arguments: ['@site.path'] ``` **web/modules/themes/custom/my_theme/my_theme.theme** ```php /** * Implements template_preprocess_html(). */ function my_theme_preprocess_html(&$variables) { // Add multisite body class. $site = \Drupal::service('my_module.helper_functions')->getMultisiteAlias(); $variables['attributes']['class'][] = 'site-' . $site; } ``` --- Read more: [When should I create a service or a utility function?][1] [1]: https://drupal.stackexchange.com/q/251111/15055