/**
  * {@inheritdoc}
  */
 public function getTableMapping()
 {
     if (!isset($this->tableMapping)) {
         $definitions = array_filter($this->getFieldStorageDefinitions(), function (FieldStorageDefinitionInterface $definition) {
             // @todo Remove the check for FieldDefinitionInterface::isMultiple() when
             //   multiple-value base fields are supported in
             //   https://drupal.org/node/2248977.
             return !$definition->hasCustomStorage() && !$definition->isMultiple();
         });
         $this->tableMapping = new DefaultTableMapping($definitions);
         $key_fields = array_values(array_filter(array($this->idKey, $this->revisionKey, $this->bundleKey, $this->uuidKey, $this->langcodeKey)));
         $all_fields = array_keys($definitions);
         $revisionable_fields = array_keys(array_filter($definitions, function (FieldStorageDefinitionInterface $definition) {
             return $definition->isRevisionable();
         }));
         // Make sure the key fields come first in the list of fields.
         $all_fields = array_merge($key_fields, array_diff($all_fields, $key_fields));
         // Nodes have all three of these fields, while custom blocks only have
         // log.
         // @todo Provide automatic definitions for revision metadata fields in
         //   https://drupal.org/node/2248983.
         $revision_metadata_fields = array_intersect(array('revision_timestamp', 'revision_uid', 'revision_log'), $all_fields);
         $revisionable = $this->entityType->isRevisionable();
         // @todo Remove the data table check once all entity types are using
         // entity query and we have a views data controller. See:
         // - https://drupal.org/node/2068325
         // - https://drupal.org/node/1740492
         $translatable = $this->entityType->getDataTable() && $this->entityType->isTranslatable();
         if (!$revisionable && !$translatable) {
             // The base layout stores all the base field values in the base table.
             $this->tableMapping->setFieldNames($this->baseTable, $all_fields);
         } elseif ($revisionable && !$translatable) {
             // The revisionable layout stores all the base field values in the base
             // table, except for revision metadata fields. Revisionable fields
             // denormalized in the base table but also stored in the revision table
             // together with the entity ID and the revision ID as identifiers.
             $this->tableMapping->setFieldNames($this->baseTable, array_diff($all_fields, $revision_metadata_fields));
             $revision_key_fields = array($this->idKey, $this->revisionKey);
             $this->tableMapping->setFieldNames($this->revisionTable, array_merge($revision_key_fields, $revisionable_fields));
         } elseif (!$revisionable && $translatable) {
             // Multilingual layouts store key field values in the base table. The
             // other base field values are stored in the data table, no matter
             // whether they are translatable or not. The data table holds also a
             // denormalized copy of the bundle field value to allow for more
             // performant queries. This means that only the UUID is not stored on
             // the data table.
             $this->tableMapping->setFieldNames($this->baseTable, $key_fields)->setFieldNames($this->dataTable, array_values(array_diff($all_fields, array($this->uuidKey))))->setExtraColumns($this->dataTable, array('default_langcode'));
         } elseif ($revisionable && $translatable) {
             // The revisionable multilingual layout stores key field values in the
             // base table, except for language, which is stored in the revision
             // table along with revision metadata. The revision data table holds
             // data field values for all the revisionable fields and the data table
             // holds the data field values for all non-revisionable fields. The data
             // field values of revisionable fields are denormalized in the data
             // table, as well.
             $this->tableMapping->setFieldNames($this->baseTable, array_values(array_diff($key_fields, array($this->langcodeKey))));
             // Like in the multilingual, non-revisionable case the UUID is not
             // in the data table. Additionally, do not store revision metadata
             // fields in the data table.
             $data_fields = array_values(array_diff($all_fields, array($this->uuidKey), $revision_metadata_fields));
             $this->tableMapping->setFieldNames($this->dataTable, $data_fields)->setExtraColumns($this->dataTable, array('default_langcode'));
             $revision_base_fields = array_merge(array($this->idKey, $this->revisionKey, $this->langcodeKey), $revision_metadata_fields);
             $this->tableMapping->setFieldNames($this->revisionTable, $revision_base_fields);
             $revision_data_key_fields = array($this->idKey, $this->revisionKey, $this->langcodeKey);
             $revision_data_fields = array_diff($revisionable_fields, $revision_metadata_fields);
             $this->tableMapping->setFieldNames($this->revisionDataTable, array_merge($revision_data_key_fields, $revision_data_fields))->setExtraColumns($this->revisionDataTable, array('default_langcode'));
         }
     }
     return $this->tableMapping;
 }