protected function DatabaseStorageControllerNG::mapToDataStorageRecord

Maps from an entity object to the storage record of the data table.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity object.

$langcode: The language code of the translation to get.

Return value

\stdClass The record to store.

2 calls to DatabaseStorageControllerNG::mapToDataStorageRecord()
DatabaseStorageControllerNG::savePropertyData in drupal/core/lib/Drupal/Core/Entity/DatabaseStorageControllerNG.php
Stores the entity property language-aware data.
NodeStorageController::mapToDataStorageRecord in drupal/core/modules/node/lib/Drupal/node/NodeStorageController.php
Maps from an entity object to the storage record of the data table.
1 method overrides DatabaseStorageControllerNG::mapToDataStorageRecord()
NodeStorageController::mapToDataStorageRecord in drupal/core/modules/node/lib/Drupal/node/NodeStorageController.php
Maps from an entity object to the storage record of the data table.

File

drupal/core/lib/Drupal/Core/Entity/DatabaseStorageControllerNG.php, line 568
Contains \Drupal\Core\Entity\DatabaseStorageControllerNG.

Class

DatabaseStorageControllerNG
Implements Field API specific enhancements to the DatabaseStorageController class.

Namespace

Drupal\Core\Entity

Code

protected function mapToDataStorageRecord(EntityInterface $entity, $langcode) {
  $default_langcode = $entity
    ->language()->langcode;

  // Don't use strict mode, this way there's no need to do checks here, as
  // non-translatable properties are replicated for each language.
  $translation = $entity
    ->getTranslation($langcode, FALSE);
  $definitions = $translation
    ->getPropertyDefinitions();
  $schema = drupal_get_schema($this->entityInfo['data_table']);
  $record = new \stdClass();
  foreach (drupal_schema_fields_sql($this->entityInfo['data_table']) as $name) {
    $info = $schema['fields'][$name];
    $value = isset($definitions[$name]) && isset($translation->{$name}->value) ? $translation->{$name}->value : NULL;
    $record->{$name} = drupal_schema_get_field_value($info, $value);
  }
  $record->langcode = $langcode;
  $record->default_langcode = intval($default_langcode == $langcode);
  return $record;
}