You are here

function field_test_field_storage_load in SimpleTest 7

Implement hook_field_storage_load().

File

tests/field_test.module, line 761

Code

function field_test_field_storage_load($obj_type, $objects, $age, $fields, $options) {
  $data = _field_test_storage_data();
  $load_current = $age == FIELD_LOAD_CURRENT;
  foreach ($fields as $field_id => $ids) {
    $field = field_info_field_by_id($field_id);
    $field_name = $field['field_name'];
    $field_data = $data[$field['id']];
    $sub_table = $load_current ? 'current' : 'revisions';
    $delta_count = array();
    foreach ($field_data[$sub_table] as $row) {
      if ($row->type == $obj_type && (!$row->deleted || $options['deleted'])) {
        if ($load_current && in_array($row->entity_id, $ids) || !$load_current && in_array($row->revision_id, $ids)) {
          if (in_array($row->language, field_multilingual_available_languages($obj_type, $field))) {
            if (!isset($delta_count[$row->entity_id][$row->language])) {
              $delta_count[$row->entity_id][$row->language] = 0;
            }
            if ($field['cardinality'] == FIELD_CARDINALITY_UNLIMITED || $delta_count[$row->entity_id][$row->language] < $field['cardinality']) {
              $item = array();
              foreach ($field['columns'] as $column => $attributes) {
                $item[$column] = $row->{$column};
              }
              $objects[$row->entity_id]->{$field_name}[$row->language][] = $item;
              $delta_count[$row->entity_id][$row->language]++;
            }
          }
        }
      }
    }
  }
}