Drupal is a registered trademark of Dries Buytaert
cms 2.1.3 Update released for Drupal core (2.1.3)! drupal 10.5.11 Update released for Drupal core (10.5.11)! drupal 11.3.11 Update released for Drupal core (11.3.11)! drupal 11.2.13 Update released for Drupal core (11.2.13)! drupal 10.6.10 Update released for Drupal core (10.6.10)! cms 2.1.2 Update released for Drupal core (2.1.2)! drupal 11.1.10 Update released for Drupal core (11.1.10)! drupal 10.5.10 Update released for Drupal core (10.5.10)! drupal 10.4.10 Update released for Drupal core (10.4.10)! drupal 11.2.12 Update released for Drupal core (11.2.12)! drupal 11.3.10 Update released for Drupal core (11.3.10)! drupal 10.6.9 Update released for Drupal core (10.6.9)! drupal 10.6.8 Update released for Drupal core (10.6.8)! drupal 11.3.9 Update released for Drupal core (11.3.9)! drupal 11.3.8 Update released for Drupal core (11.3.8)! drupal 11.3.7 Update released for Drupal core (11.3.7)! drupal 11.2.11 Update released for Drupal core (11.2.11)! drupal 10.6.7 Update released for Drupal core (10.6.7)! drupal 10.5.9 Update released for Drupal core (10.5.9)! cms 2.1.1 Update released for Drupal core (2.1.1)!

Enum Generator provides a means of generating enums or class constants files from your site's entities/entity types. At initial release it only supports taxonomy vocabularies/terms, but the hope is to extend it to entity types in the future. The module provides a form from which you can input/select:

  • The namespace to use for the generated file
  • Whether to generate an enum file or class of constants. This might be helpful depending on your PHP version.
  • Whether to cast the IDs to strings or integers.

Generators are available from /admin/structure/enum-generator. For a vocabulary called "Animals" containing three terms, the generated files would look like:

<?php

namespace Drupal\my_module\Enum;

/**
 * Defines enums for terms in the Animals taxonomy.
 */
enum AnimalsTerm: int
{
	/** Represents the "Cat" term. */
	case CAT = 37;

	/** Represents the "Dog" term. */
	case DOG = 36;

	/** Represents the "FISH" term. */
	case FISH = 35;
}
<?php

namespace Drupal\my_module\ConstEnum;

/**
 * Defines class constants for terms in the Animals taxonomy.
 */
class AnimalsTerm
{
	/** Represents the "Cat" term. */
	public const CAT = 37;

	/** Represents the "Dog" term. */
	public const DOG = 36;

	/** Represents the "Fish" term. */
	public const FISH = 35;
}

The file contents are generated by https://github.com/nette/php-generator, so they do not follow Drupal style guidelines at the moment.

Shameless Self Promotion

A list of modules that I maintain:

  • Cache Register: A module aimed at improving developer quality of life surrounding caching.
  • Enum Generator: A developer utility that generates enums and class constants from a site's entities.
  • Views Hooks Extras: Extends Views' native hooks to more specifically target particular views and their displays
  • Media Entity Remote Image: Provides a simple media type + field for remote image urls

Activity

Total releases
1
First release
Jan 2026
Latest release
4 months ago
Release cadence
Stability
100% stable

Releases

Version Type Release date
1.0.1 Stable Jan 26, 2026