I defined an enum in a custom module:
namespace Drupal\my_module\Enum;
enum BuildType: string {
case Apple = 'apple_build';
case Orange = 'orange_build';
}
And I want to use it in settings.php to change the config directory of the site:
settings.php:
$build_type = BuildType::from(getenv('build_type'));
$settings['config_sync_directory'] = dirname(DRUPAL_ROOT) . '/config/base_' . $build_type->value;
$settings['custom_translations_directory'] = dirname(DRUPAL_ROOT) . '/translations/' . $build_type->value;
However, when I do this, I get a namespace error:
Error: Class "Drupal\my_module\Enum\BuildType" not found in /var/www/html/web/sites/default/settings.custom.php on line 14 #0 /var/www/html/web/sites/default/settings.php(32): include()
How can I correctly namespace my enum for use in settings.php?
Drupal\my_module\Enum\BuildType
, it must beuse Drupal\my_module\Enum\BuildType;
.