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 = TRUEdata_table,revision_table,revision_data_table"revision" = "revision_id"and"langcode" = "langcode"inentity_keys->setTranslatable(TRUE)and->setRevisionable(TRUE)on thetitlefield
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
- Run
drush generate subentityand complete the interview. - Open the generated entity class.
- Observe that
translatable = TRUE, revision tables, andsetRevisionable(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 translatablerevision_tableandrevision_data_table— only when revisionabletranslatable = TRUE— only when translatable"revision" = "revision_id"inentity_keys— only when revisionable"langcode" = "langcode"inentity_keys— only when translatable->setTranslatable(TRUE)on thetitlefield — only when translatable->setRevisionable(TRUE)on thetitlefield — 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
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
Comment #4
macsim commentedThanks, code looked good to me
I added unit tests for translatable/revisionable generator conditionals
Pipeline is green - needs review and manual testing
Comment #5
maxpahComment #7
maxpah