function field_test_entity_save

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.

16 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

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);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.