function field_test_entity_save
7.x field_test.entity.inc | field_test_entity_save(&$entity) |
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.
12 calls to field_test_entity_save()
- FieldDisplayAPITestCase::setUp in drupal-7.x/
modules/ field/ tests/ field.test - Set the default field storage backend for fields created during tests.
- FieldFormTestCase::testNestedFieldForm in drupal-7.x/
modules/ field/ tests/ field.test - Tests Field API form integration within a subform.
- FieldTranslationsTestCase::testFieldFormTranslationRevisions in drupal-7.x/
modules/ field/ tests/ field.test - Tests field translations when creating a new revision.
- field_test_entity_form_submit in drupal-7.x/
modules/ field/ tests/ field_test.entity.inc - Submit handler for field_test_entity_form().
- field_test_entity_nested_form_submit in drupal-7.x/
modules/ field/ tests/ field_test.entity.inc - Submit handler for field_test_entity_nested_form().
File
- drupal-7.x/
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);
}