GravityKit\GravityMigrate\Schema\MergeTagTranslator
Translates system merge tags between platforms through one map per platform.
Each platform declares how it spells each value the universal model names, once, in its own definition. Reading and writing both come from that one map, so the two directions cannot disagree.
A tag with no equivalent on the far side is reported rather than dropped or passed through. Passed through, the other platform prints it verbatim in an email somebody receives; dropped, a value somebody deliberately put in a sentence is gone. The caller decides which.
Since: %ver%
Source: src/Schema/MergeTagTranslator.php:25
Details
- Kind:
class - Namespace:
GravityKit\GravityMigrate\Schema
Methods
| Method | Description |
|---|---|
translate() | Rewrites every system tag in some text from one platform's spelling to another's. |
keyed_tags_of() | How one platform spells the tags that carry a key. |
tags_of() | What one platform calls each value, or nothing when it does not declare them. |
aliases_of() | The other spellings a platform accepts for a value it already names. |
resolved_values_of() | The values a platform writes out as the value itself rather than as a tag of its own. |
unsupported_by() | The values a platform has no way to say. |
report_unmapped() | Reports the tags in the text that the origin plugin knows and the map does not. |
untranslatable_on() | The tags the plugin declares that this plugin's map has no value for. |
Method Reference
translate()
public static function translate( string $text, string $from_platform, string $to_platform, array&$untranslated=[] ): string
Rewrites every system tag in some text from one platform's spelling to another's.
Field references are not handled here. A field reference follows the field to whatever identifier it was given on the other platform, which is the field map's business, and its syntax differs per platform, so each platform's own adapter rewrites it.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$text | string | Text containing tags. | |
$from_platform | string | Platform the text was written for. | |
$to_platform | string | Platform it is being written for. | |
&$untranslated | array | [] | Filled with the tags that have no equivalent, by reference. |
Returns
string
Since: %ver%
Source: src/Schema/MergeTagTranslator.php:43
keyed_tags_of()
public static function keyed_tags_of( string $platform ): array
How one platform spells the tags that carry a key.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$platform | string | Canonical platform id. |
Returns
array<string,— string>
Since: %ver%
Source: src/Schema/MergeTagTranslator.php:213
tags_of()
public static function tags_of( string $platform ): array
What one platform calls each value, or nothing when it does not declare them.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$platform | string | Canonical platform id. |
Returns
array<string,— string>
Since: %ver%
Source: src/Schema/MergeTagTranslator.php:232
aliases_of()
public static function aliases_of( string $platform ): array
The other spellings a platform accepts for a value it already names.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$platform | string | Canonical platform id. |
Returns
array<string,— string> Spelling to universal value.
Since: %ver%
Source: src/Schema/MergeTagTranslator.php:260
resolved_values_of()
public static function resolved_values_of( string $platform ): array
The values a platform writes out as the value itself rather than as a tag of its own.
The values are resolved at the time of the migration, which is why this is a method rather than a constant.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$platform | string | Canonical platform id. |
Returns
array<string,— string> Universal value name to the text written in its place.
Since: %ver%
Source: src/Schema/MergeTagTranslator.php:282
unsupported_by()
public static function unsupported_by( string $platform ): array
The values a platform has no way to say.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$platform | string | Canonical platform id. |
Returns
string[]— Universal value names, not spellings. Empty when the platform declares no tags at all, which is not the same as it saying everything.
Since: %ver%
Source: src/Schema/MergeTagTranslator.php:324
report_unmapped()
public static function report_unmapped( string $text, string $from_platform, array&$untranslated ): string
Reports the tags in the text that the origin plugin knows and the map does not.
The swap above walks the map, so a tag nowhere in the map is neither swapped nor noticed: it
goes through untouched and the destination, which cannot resolve it, prints it. WS Form fills
a textarea's help with #character_count #character_count_label / #word_count #word_count_label by default, so every textarea on a real site carries four of them and the
migrated field shows that string under the box as its description.
Nothing is removed here. The caller decides — a notification body and a field's wording want different handling — and the list is ordered so that removing it in order is safe.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$text | string | Text after the mapped tags have been swapped. | |
$from_platform | string | Platform the text was written for. | |
&$untranslated | array | Appended to with the tags that have no equivalent, by reference. |
Returns
string— The text, unchanged.
Since: %ver%
Source: src/Schema/MergeTagTranslator.php:358
untranslatable_on()
public static function untranslatable_on( string $platform ): array
The tags the plugin declares that this plugin's map has no value for.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$platform | string | Canonical platform id. |
Returns
string[]— Tag literals the plugin knows and this does not.
Since: %ver%
Source: src/Schema/MergeTagTranslator.php:439