You are here

function ctools_export_crud_save in Chaos Tool Suite (ctools) 6

Same name and namespace in other branches
  1. 7 includes/export.inc \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

2 calls to ctools_export_crud_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 137
Contains code to make it easier to have exportable objects.

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