Is it possible to mark only a single property of a field as translateable?
E.g. I have a custom field type RoomRates
with 2 properties uri
and price_mode
.
/**
* Plugin implementation of the 'kognitiv_room_rate' field type.
*
* @FieldType(
* id = "kognitiv_room_rate",
* label = @Translation("Kognitiv room rate"),
* description = @Translation("Stores an URL to retrieve price and availability data for a room"),
* default_widget = "kognitiv_room_rate",
* default_formatter = "kognitiv_room_rate",
* cardinality = 1,
* column_groups = {
* "uri" = {
* "label" = @Translation("URI"),
* "translatable" = TRUE
* },
* "price_mode" = {
* "label" = @Translation("Show prices as")
* }
* }
* )
*/
class RoomRate extends FieldItemBase implements LinkItemInterface {
const PRICE_MODE_PERSON = 'PERSON';
const PRICE_MODE_DAY = 'DAY';
public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
$properties['uri'] = DataDefinition::create('uri')
->setLabel(t('URI'))
->setRequired(TRUE);
$properties['price_mode'] = DataDefinition::create('string')
->setLabel(t('Show prices as'))
->setRequired(TRUE);
return $properties;
}
/**
* {@inheritdoc}
*/
public static function schema(FieldStorageDefinitionInterface $field_definition) {
return [
'columns' => [
'uri' => [
'description' => 'The URI of the JSON API endpoint.',
'type' => 'varchar',
'length' => 2048,
],
'price_mode' => [
'description' => 'Show prices as price per day or price per person in std occupancy',
'type' => 'varchar',
'length' => 10,
],
],
'indexes' => [],
'foreign keys' => [],
];
}
The uri
property should be translateable (if the site builder enables translation for this field), while the price_mode
property should never be translateable/always be the same accross all languages (no matter if the site builder enabled field translation or not).