protected function EntityTestStorageController::postSave

Overrides Drupal\Core\Entity\DatabaseStorageController::postSave().

Stores values of translatable properties.

Overrides DatabaseStorageController::postSave

File

drupal/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/EntityTestStorageController.php, line 92
Definition of Drupal\entity_test\EntityTestStorageController.

Class

EntityTestStorageController
Defines the controller class for the test entity.

Namespace

Drupal\entity_test

Code

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

  // Delete and insert to handle removed values.
  db_delete('entity_test_property_data')
    ->condition('id', $entity
    ->id())
    ->execute();
  $query = db_insert('entity_test_property_data');
  foreach ($entity
    ->getTranslationLanguages() as $langcode => $language) {
    $translation = $entity
      ->getTranslation($langcode);
    $values = array(
      'id' => $entity
        ->id(),
      'revision_id' => $entity
        ->getRevisionId(),
      'langcode' => $langcode,
      'default_langcode' => intval($default_langcode == $langcode),
      'name' => $translation->name->value,
      'user_id' => $translation->user_id->value,
    );
    $query
      ->fields(array_keys($values))
      ->values($values);
  }
  $query
    ->execute();
}