Drupal is a registered trademark of Dries Buytaert
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)! drupal 11.3.6 Update released for Drupal core (11.3.6)! drupal 10.6.6 Update released for Drupal core (10.6.6)! cms 2.1.0 Update released for Drupal core (2.1.0)! bootstrap 8.x-3.40 Minor update available for theme bootstrap (8.x-3.40). menu_link_attributes 8.x-1.7 Minor update available for module menu_link_attributes (8.x-1.7). eca 3.1.1 Minor update available for module eca (3.1.1). layout_paragraphs 2.1.3 Minor update available for module layout_paragraphs (2.1.3). ai 1.3.3 Minor update available for module ai (1.3.3). ai 1.2.14 Minor update available for module ai (1.2.14). node_revision_delete 2.0.3 Minor update available for module node_revision_delete (2.0.3). moderated_content_bulk_publish 2.0.52 Minor update available for module moderated_content_bulk_publish (2.0.52). klaro 3.0.10 Minor update available for module klaro (3.0.10). klaro 3.0.9 Minor update available for module klaro (3.0.9). layout_paragraphs 2.1.2 Minor update available for module layout_paragraphs (2.1.2). geofield_map 11.1.8 Minor update available for module geofield_map (11.1.8).

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
2 months ago
Release cadence
Stability
100% stable

Releases

Version Type Release date
1.0.1 Stable Jan 26, 2026