You are here

function field_test_entity_save in Drupal 7

Saves a test_entity.

A new entity is created if $entity->ftid and $entity->is_new are both empty. A new revision is created if $entity->revision is not empty.

Parameters

$entity: The entity to save.

15 calls to field_test_entity_save()
FieldDisplayAPITestCase::setUp in modules/field/tests/field.test
Set the default field storage backend for fields created during tests.
FieldFormTestCase::testNestedFieldForm in modules/field/tests/field.test
Tests Field API form integration within a subform.
FieldSqlStorageTestCase::testFieldSqlStorageMultipleConditionsDifferentColumns in modules/field/modules/field_sql_storage/field_sql_storage.test
Test handling multiple conditions on multiple columns of one field.
FieldSqlStorageTestCase::testFieldSqlStorageMultipleConditionsDifferentColumnsMultipleLanguages in modules/field/modules/field_sql_storage/field_sql_storage.test
Test handling multiple conditions on multiple columns of one field for multiple languages.
FieldSqlStorageTestCase::testFieldSqlStorageMultipleConditionsSameColumn in modules/field/modules/field_sql_storage/field_sql_storage.test
Test handling multiple conditions on one column of a field.

... See full list

File

modules/field/tests/field_test.entity.inc, line 282
Defines an entity type.

Code

function field_test_entity_save(&$entity) {
  field_attach_presave('test_entity', $entity);
  if (!isset($entity->is_new)) {
    $entity->is_new = empty($entity->ftid);
  }
  if (!$entity->is_new && !empty($entity->revision)) {
    $entity->old_ftvid = $entity->ftvid;
    unset($entity->ftvid);
  }
  $update_entity = TRUE;
  if ($entity->is_new) {
    drupal_write_record('test_entity', $entity);
    drupal_write_record('test_entity_revision', $entity);
    $op = 'insert';
  }
  else {
    drupal_write_record('test_entity', $entity, 'ftid');
    if (!empty($entity->revision)) {
      drupal_write_record('test_entity_revision', $entity);
    }
    else {
      drupal_write_record('test_entity_revision', $entity, 'ftvid');
      $update_entity = FALSE;
    }
    $op = 'update';
  }
  if ($update_entity) {
    db_update('test_entity')
      ->fields(array(
      'ftvid' => $entity->ftvid,
    ))
      ->condition('ftid', $entity->ftid)
      ->execute();
  }

  // Save fields.
  $function = "field_attach_{$op}";
  $function('test_entity', $entity);
}