Problem/Motivation

The generator always produces a fully translatable and revisionable subentity regardless of whether the developer needs those features. The generated entity class hardcodes the following in the annotation and in baseFieldDefinitions():

  • translatable = TRUE
  • data_table, revision_table, revision_data_table
  • "revision" = "revision_id" and "langcode" = "langcode" in entity_keys
  • ->setTranslatable(TRUE) and ->setRevisionable(TRUE) on the title field

Enabling revision and translation support adds database tables and complexity that many subentities do not need. Developers currently have to manually strip these out after generating.

Steps to reproduce

  1. Run drush generate subentity and complete the interview.
  2. Open the generated entity class.
  3. Observe that translatable = TRUE, revision tables, and setRevisionable(TRUE) are always present with no way to opt out during generation.

Proposed resolution

Add two questions to the generator interview:

Translatable? (yes)
Revisionable? (yes)

Update generator/subentity.php.twig to wrap the relevant annotation keys and field method calls in Twig conditionals:

  • data_table — only when translatable
  • revision_table and revision_data_table — only when revisionable
  • translatable = TRUE — only when translatable
  • "revision" = "revision_id" in entity_keys — only when revisionable
  • "langcode" = "langcode" in entity_keys — only when translatable
  • ->setTranslatable(TRUE) on the title field — only when translatable
  • ->setRevisionable(TRUE) on the title field — only when revisionable

Defaults remain yes for both options to preserve the current generated output for existing users.

Remaining tasks

  • Write the MR.

User interface changes

Two new prompts in the drush generate subentity interview: Translatable? and Revisionable?

API changes

None.

Data model changes

None.

Issue fork subentity-3604201

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

macsim created an issue. See original summary.

maxpah made their first commit to this issue’s fork.

macsim’s picture

Status: Active » Needs review

Thanks, code looked good to me
I added unit tests for translatable/revisionable generator conditionals
Pipeline is green - needs review and manual testing

maxpah’s picture

Status: Needs review » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

maxpah’s picture

Status: Fixed » Closed (fixed)