You are here

function ctools_export_new_object in Chaos Tool Suite (ctools) 7

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

Create a new object based upon schema values.

Because 'default' has ambiguous meaning on some fields, we will actually use 'object default' to fill in default values if default is not set That's a little safer to use as it won't cause weird database default situations.

3 calls to ctools_export_new_object()
ctools_content_type_new in ctools_custom_content/ctools_custom_content.module
Create callback for creating a new CTools custom content type.
ctools_export_crud_new in includes/export.inc
Create a new object for the given $table.
page_manager_page_new in page_manager/plugins/tasks/page.inc
Create a new page with defaults appropriately set from schema.

File

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

Code

function ctools_export_new_object($table, $set_defaults = TRUE) {
  $schema = ctools_export_get_schema($table);
  $export = $schema['export'];
  $object = new $export['object']();
  foreach ($schema['fields'] as $field => $info) {
    if (isset($info['object default'])) {
      $object->{$field} = $info['object default'];
    }
    elseif (isset($info['default'])) {
      $object->{$field} = $info['default'];
    }
    else {
      $object->{$field} = NULL;
    }
  }
  if ($set_defaults) {

    // Set some defaults so this data always exists.
    // We don't set the export_type property here, as this object is not saved
    // yet. We do give it NULL so we don't generate notices trying to read it.
    $object->export_type = NULL;
    $object->{$export['export type string']} = t('Local');
  }
  return $object;
}