protected function EntityTestStorageController::attachPropertyData

Attaches property data in all languages for translatable properties.

1 call to EntityTestStorageController::attachPropertyData()
EntityTestStorageController::mapFromStorageRecords in drupal/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/EntityTestStorageController.php
Maps from storage records to entity objects.

File

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

Class

EntityTestStorageController
Defines the controller class for the test entity.

Namespace

Drupal\entity_test

Code

protected function attachPropertyData(&$queried_entities, $load_revision = FALSE) {
  $query = db_select('entity_test_property_data', 'data', array(
    'fetch' => PDO::FETCH_ASSOC,
  ))
    ->fields('data')
    ->condition('id', array_keys($queried_entities))
    ->orderBy('data.id');
  if ($load_revision) {

    // Get revision id's.
    $revision_ids = array();
    foreach ($queried_entities as $id => $entity) {
      $revision_ids[] = $entity
        ->get('revision_id')->value;
    }
    $query
      ->condition('revision_id', $revision_ids);
  }
  $data = $query
    ->execute();
  foreach ($data as $values) {
    $id = $values['id'];

    // Field values in default language are stored with
    // LANGUAGE_DEFAULT as key.
    $langcode = empty($values['default_langcode']) ? $values['langcode'] : LANGUAGE_DEFAULT;
    $queried_entities[$id]->name[$langcode][0]['value'] = $values['name'];
    $queried_entities[$id]->user_id[$langcode][0]['value'] = $values['user_id'];
  }
}