What's the best way to assign variables for use in multiple form modules? We have multiple custom form modules in our Drupal 8 site, and there are variables that are common across them -- like arrays for year, semester and campus, as well as lists of courses (so it's quite a few values, and they have to be updated from time to time). What's the best (most correct) way to define these common variables in a single place so they can be accessed by any module that needs them?
It's hard to say what is the &quot;best&quot;, but you can write a class, add the variables as constants, and then import the class wherever you need it.
For example, in MYMODULE/src/MyVariables.php:
&lt;?php

namespace Drupal\MYMODULE\SharedStuff;
    
/**
 * Defines variables that need to be shared throughout the site.
 */
class MyVariables {

  // Seconds in an hour.
  const HOUR = 60 * 60;
  // Seconds in a day.
  const DAY = 24 * self::HOUR;
  // Seconds in a week.
  const WEEK = 7 * self::DAY;
}

And then in the PHP files where you need the variables:
use Drupal\MYMODULE\SharedStuff\MyVariables;
And then for the variable: MyVariables::HOUR