function ctools_export_crud_import

Turn exported code into an object.

Note: If the code is poorly formed, this could crash and there is no way to prevent this.

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.

$code: The code to eval to create the object.

Return value

An object created from the export. This object will NOT have been saved to the database. In the case of failure, a string containing all errors that the system was able to determine.

Related topics

2 calls to ctools_export_crud_import()
ctools_export_ui::clone_page in plugins/export_ui/ctools_export_ui.class.php
Main entry point to clone an item.
ctools_export_ui::edit_form_import_validate in plugins/export_ui/ctools_export_ui.class.php
Import form validate handler.

File

includes/export.inc, line 271

Code

function ctools_export_crud_import($table, $code) {
    $schema = ctools_export_get_schema($table);
    $export = $schema['export'];
    if (!empty($export['import callback']) && function_exists($export['import callback'])) {
        return $export['import callback']($code);
    }
    else {
        ob_start();
        eval($code);
        ob_end_clean();
        if (empty(${$export['identifier']})) {
            $errors = ob_get_contents();
            if (empty($errors)) {
                $errors = t('No item found.');
            }
            return $errors;
        }
        $item = ${$export['identifier']};
        // Set these defaults just the same way that ctools_export_new_object sets
        // them.
        $item->export_type = NULL;
        $item->{$export['export type string']} = t('Local');
        return $item;
    }
}