Download & Extend

Support for data tables in the default entity storage controller

Project: 
Drupal core
Introduced in branch: 
8.x
Description: 

The default DatabaseStorageControllerNG (@todo: Remove NG once merged back into the default controller) now support data tables, which are used for making entity fields translatable.

To support translatable fields, an entity type just needs to define the data table in the entity type definition like this:

<?php
/**
* Defines the test entity class.
*
* @EntityType(
*   id = "entity_test_mulrev",
*   label = @Translation("Test entity - revisions and data table"),
*   base_table = "entity_test_mulrev",
*   data_table = "entity_test_mulrev_property_data",
*   revision_table = "entity_test_mulrev_property_revision",
* )
*/
?>

and flag the fields that are translatable and should be stored in that table accordingly in their baseFieldDefinitions() method of the storage controller:

<?php
 
/**
   * Implements \Drupal\Core\Entity\DataBaseStorageControllerNG::baseFieldDefinitions().
   */
 
public function baseFieldDefinitions() {
   
// ...
   
$fields['name'] = array(
     
'label' => t('Name'),
     
'description' => t('The name of the test entity.'),
     
'type' => 'string_field',
     
'translatable' => TRUE,
    );
   
$fields['user_id'] = array(
     
'label' => t('User ID'),
     
'description' => t('The ID of the associated user.'),
     
'type' => 'entityreference_field',
     
'settings' => array('entity type' => 'user'),
     
'translatable' => TRUE,
    );
    return
$fields;
  }
?>

All fields that can vary per language (in the above example, the name and user id of the author) should be marked translatable.

Impacts: 
Module developers
Updates Done (doc team, etc.)
Online documentation: 
Not done
Theming guide: 
Not done
Module developer documentation: 
Not done
Examples project: 
Not done
Coder Review: 
Not done
Coder Upgrade: 
Not done
Other: 
Other updates done