Skip to content

Add translation() => getOrCreateTranslation() rector rule for 6.x#388

Open
dereuromark wants to merge 1 commit into6.xfrom
feature/translation-rector-6x
Open

Add translation() => getOrCreateTranslation() rector rule for 6.x#388
dereuromark wants to merge 1 commit into6.xfrom
feature/translation-rector-6x

Conversation

@dereuromark
Copy link
Member

Summary

Adds a Rector rule for CakePHP 6.0 that transforms $entity->translation('lang') calls to $entity->getOrCreateTranslation('lang').

In CakePHP 6.0, TranslateTrait::translation() becomes a pure getter that returns null if no translation exists. The old create-on-access behavior (creating an empty translation entity and marking it dirty) is now in getOrCreateTranslation().

This rector rule preserves backward compatibility by renaming translation() calls to getOrCreateTranslation(), which maintains the same behavior as before the change.

Before:

$article->translation('fra');  // Creates entity if missing, marks dirty

After:

$article->getOrCreateTranslation('fra');  // Same behavior as old translation()

Refs: cakephp/cakephp#19251

@dereuromark dereuromark changed the base branch from 5.x to 6.x February 12, 2026 04:04
In CakePHP 6.0, TranslateTrait::translation() becomes a pure getter
that returns null if no translation exists. The old create-on-access
behavior is now in getOrCreateTranslation().

This rector transforms $entity->translation('lang') calls to
$entity->getOrCreateTranslation('lang') to preserve backward
compatibility during the upgrade.

See: cakephp/cakephp#19251
@dereuromark dereuromark force-pushed the feature/translation-rector-6x branch from f23c6b0 to c225d66 Compare February 12, 2026 04:09
@dereuromark dereuromark added this to the 6.x milestone Feb 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant