docs: Port "Implementing translation support to entities" page to 7.2#576
Conversation
| .. vale on No newline at end of file | ||
| .. vale on | ||
|
|
||
| Mautic provides helper interfaces and traits that add translated-content support to an entity. Use them so your entity can store a language, relate to a translation parent, and resolve the correct translation at runtime. |
There was a problem hiding this comment.
Ported this page from the legacy _plugin_misc_translated_entities.md source referenced by porting issue #414, converting its Markdown headings and code block into RST.
| ``Mautic\CoreBundle\Entity\TranslationEntityTrait`` | ||
| This trait provides the properties and methods that define an entity's language and its relationships to its translation parent and children. In the entity's ``loadMetadata()`` method, call ``self::addTranslationMetadata($builder, self::class)`` to map the translation columns and relationships. | ||
|
|
||
| ``Mautic\CoreBundle\Model\TranslationModelTrait`` |
There was a problem hiding this comment.
Corrected the legacy TranslationInterface name to TranslationEntityInterface and updated addTranslationMetadata() to the current static signature self::addTranslationMetadata($builder, self::class), verified against TranslationEntityTrait and TranslationEntityInterface in mautic/mautic 7.x.
Source: https://github.com/mautic/mautic/blob/7.x/app/bundles/CoreBundle/Entity/TranslationEntityTrait.php
| ``Mautic\CoreBundle\Model\TranslationModelTrait`` | ||
| Use this trait in the entity's model. It provides ``getTranslatedEntity()``, which determines the entity to use as the translation based on the Contact and/or the request's ``Accept-Language`` header, and ``postTranslationEntitySave()``, which you call at the end of the model's ``saveEntity()`` method to persist the translation relationship. | ||
|
|
||
| .. vale off |
There was a problem hiding this comment.
Fixed the namespace of TranslationModelTrait to Mautic\CoreBundle\Model (legacy docs put it under Entity) and confirmed getTranslatedEntity() and postTranslationEntitySave() exist there in mautic/mautic 7.x.
Source: https://github.com/mautic/mautic/blob/7.x/app/bundles/CoreBundle/Model/TranslationModelTrait.php
| 'label_attr' => ['class' => 'control-label'], | ||
| 'attr' => [ | ||
| 'class' => 'form-control', | ||
| 'tooltip' => 'mautic.core.form.translation_parent.help', |
There was a problem hiding this comment.
Modernized the Form example from the legacy Symfony 2 string types to the current PageType pattern: translationParent via a *ListType with IdToEntityModelTransformer and language via LocaleType, matching how PageType in mautic/mautic 7.x builds these fields.
Source: https://github.com/mautic/mautic/blob/7.x/app/bundles/PageBundle/Form/Type/PageType.php
Open this suggestion in Promptless to view citations and reasoning process
Ports the legacy translated-entity guide into docs/plugin_miscellaneous/translated_entities.rst (converted from Markdown to RST), replacing the placeholder note with code-level content: the TranslationEntityInterface, TranslationEntityTrait, and TranslationModelTrait helpers, plus a translated-entity Form example. References were verified against mautic/mautic 7.x and updated from the stale legacy names (e.g. TranslationInterface -> TranslationEntityInterface; TranslationMigrationTrait/addTranslationSchema omitted as removed in 6.0). Resolves docs issue #415; targets the 7.2 base branch per the team's porting decision.
Trigger Events
blockedlabel is to set content, structure, and tone in one branch, then backport/cherry pick i...Tip: Add or adjust Promptless's style guide in Agent Knowledge Base ✍️