Skip to main content
Drupal is a registered trademark of Dries Buytaert
Release: OpenID Connect / OAuth client 3.0.0-alpha9 New alpha version released for module openid_connect (3.0.0-alpha9). Release: Opensolr Search 4.5.0 Minor update available for module opensolr_search (4.5.0). Release: Timelinr 1.0.1 Minor update available for module timelinr (1.0.1). Usage Milestone: Simplify Module simplify crossed 10,000 active installs. Usage Milestone: Views Reference Filter Module entityreference_filter crossed 10,000 active installs. Usage Milestone: Dropdown Language Module dropdown_language crossed 10,000 active installs. Usage Milestone: Paragraphs Browser Module paragraphs_browser crossed 10,000 active installs. Usage Milestone: OpenAPI Module openapi crossed 10,000 active installs. Usage Milestone: Decoupled Router Module decoupled_router crossed 10,000 active installs. Module Revived: Entityqueue Buttons 1.1.2 Module entityqueue_buttons updated after 8 months of inactivity (1.1.2).

Enum Generator

Security covered Drupal 9–11
View on drupal.org

This module generates PHP enum or class constant files based on your Drupal site's taxonomy vocabularies, allowing you to easily define named constants for your terms. It provides options for namespace, output format (enum or constants), and ID casting.

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

Depends on

Dependencies of the latest stable release

Required by

Tracked projects that depend on this one

No tracked projects depend on this one yet.

Activity

Tracked releases
2
Tracked since
Feb 2025
Latest release
7 months ago
Releases (12 mo)
1
Maintenance
Active

Releases

Version Type Core Release date
1.0.1 Stable 9–11 Jan 26, 2026
1.0.0 Stable 8–10 Feb 28, 2025