function ctools_export_crud_save

Save a single exportable object.

Parameters

$table: The name of the table to use to retrieve $schema values. This table must have an 'export' section containing data or this function will fail.

$object: The fully populated object to save.

Return value

Failure to write a record will return FALSE. Otherwise SAVED_NEW or SAVED_UPDATED is returned depending on the operation performed. The $object parameter contains values for any serial fields defined by the $table

Related topics

4 calls to ctools_export_crud_save()
CtoolsExportCrudTestCase::testCrudExportDelete in tests/ctools_export_test/ctools_export.test
Tests CRUD operation: Delete.
CtoolsExportCrudTestCase::testCrudExportSave in tests/ctools_export_test/ctools_export.test
Tests CRUD operation: Save.
ctools_export_ui::edit_save_form in plugins/export_ui/ctools_export_ui.class.php
Called to save the final product from the edit form.
_ctools_custom_content_type_edit_save in plugins/content_types/custom/custom.inc

File

includes/export.inc, line 168

Code

function ctools_export_crud_save($table, &$object) {
    $schema = ctools_export_get_schema($table);
    $export = $schema['export'];
    if (!empty($export['save callback']) && function_exists($export['save callback'])) {
        return $export['save callback']($object);
    }
    else {
        // Objects should have a serial primary key. If not, simply fail to write.
        if (empty($export['primary key'])) {
            return FALSE;
        }
        $key = $export['primary key'];
        if ($object->export_type & EXPORT_IN_DATABASE) {
            // Existing record.
            $update = array(
                $key,
            );
        }
        else {
            // New record.
            $update = array();
            $object->export_type = EXPORT_IN_DATABASE;
        }
        return drupal_write_record($table, $object, $update);
    }
}