You are here

function ctools_export_get_schema in Chaos Tool Suite (ctools) 6

Same name and namespace in other branches
  1. 7 includes/export.inc \ctools_export_get_schema()

Get the schema for a given table.

This looks for data the export subsystem needs and applies defaults so that it's easily available.

24 calls to ctools_export_get_schema()
ctools_export_crud_delete in includes/export.inc
Delete a single exportable object.
ctools_export_crud_export in includes/export.inc
Get the exported code of a single exportable object.
ctools_export_crud_import in includes/export.inc
Turn exported code into an object.
ctools_export_crud_load in includes/export.inc
Load a single exportable object.
ctools_export_crud_load_all in includes/export.inc
Load all exportable objects of a given type.

... See full list

File

includes/export.inc, line 761
Contains code to make it easier to have exportable objects.

Code

function ctools_export_get_schema($table) {
  $cache =& ctools_static(__FUNCTION__);
  if (empty($cache[$table])) {
    $schema = drupal_get_schema($table);
    if (!isset($schema['export'])) {
      return array();
    }
    if (empty($schema['module'])) {
      return array();
    }

    // Add some defaults
    $schema['export'] += array(
      'key' => 'name',
      'key name' => 'Name',
      'object' => 'stdClass',
      'status' => 'default_' . $table,
      'default hook' => 'default_' . $table,
      'can disable' => TRUE,
      'identifier' => $table,
      'primary key' => !empty($schema['primary key']) ? $schema['primary key'][0] : '',
      'bulk export' => TRUE,
      'list callback' => "{$schema['module']}_{$table}_list",
      'to hook code callback' => "{$schema['module']}_{$table}_to_hook_code",
      'export type string' => 'type',
    );

    // If the export definition doesn't have the "primary key" then the CRUD
    // save callback won't work.
    if (empty($schema['export']['primary key']) && user_access('administer site configuration')) {
      drupal_set_message(t('The export definition of @table is missing the "primary key" property.', array(
        '@table' => $table,
      )), 'error');
    }

    // Notes:
    // The following callbacks may be defined to override default behavior
    // when using CRUD functions:
    //
    // create callback
    // load callback
    // load all callback
    // save callback
    // delete callback
    // export callback
    // import callback
    //
    // See the appropriate ctools_export_crud function for details on what
    // arguments these callbacks should accept. Please do not call these
    // directly, always use the ctools_export_crud_* wrappers to ensure
    // that default implementations are honored.
    $cache[$table] = $schema;
  }
  return $cache[$table];
}