function _ctools_export_get_defaults

Get export object defaults.

Call the hook to get all default objects of the given type from the export. If configured properly, this could include loading up an API to get default objects.

Parameters

string $table: The name of the table to be loaded. Data is expected to be in the schema to make all this work.

array $export: The export definition from the table's hook_schema() definition.

3 calls to _ctools_export_get_defaults()
ctools_export_load_object in includes/export.inc
Load some number of exportable objects.
ctools_get_default_object in includes/export.inc
Get the default version of an object, if it exists.
_ctools_export_get_some_defaults in includes/export.inc
Get a limited number of default objects.
1 string reference to '_ctools_export_get_defaults'
ctools_export_load_object_reset in includes/export.inc
Reset all static caches in ctools_export_load_object() or static caches for a given table in ctools_export_load_object().

File

includes/export.inc, line 652

Code

function _ctools_export_get_defaults($table, array $export) {
    $cache =& drupal_static(__FUNCTION__, array());
    // If defaults may be cached, first see if we can load from cache.
    if (!isset($cache[$table]) && !empty($export['cache defaults'])) {
        $cache[$table] = _ctools_export_get_defaults_from_cache($table, $export);
    }
    if (!isset($cache[$table])) {
        // If we're caching, attempt to get a lock. We will wait a short time
        // on the lock, but not too long, because it's better to just rebuild
        // and throw away results than wait too long on a lock.
        if (!empty($export['cache defaults'])) {
            for ($counter = 0; !($lock = lock_acquire('ctools_export:' . $table)) && $counter > 5; $counter++) {
                lock_wait('ctools_export:' . $table, 1);
                ++$counter;
            }
        }
        $cache[$table] = array();
        if ($export['default hook']) {
            if (!empty($export['api'])) {
                ctools_include('plugins');
                $info = ctools_plugin_api_include($export['api']['owner'], $export['api']['api'], $export['api']['minimum_version'], $export['api']['current_version']);
                $modules = array_keys($info);
            }
            else {
                $modules = module_implements($export['default hook']);
            }
            foreach ($modules as $module) {
                $function = $module . '_' . $export['default hook'];
                if (function_exists($function)) {
                    foreach ((array) $function($export) as $name => $object) {
                        // Record the module that provides this exportable.
                        $object->export_module = $module;
                        if (empty($export['api'])) {
                            $cache[$table][$name] = $object;
                        }
                        else {
                            // If version checking is enabled, ensure that the object can be
                            // used.
                            if (isset($object->api_version) && version_compare($object->api_version, $export['api']['minimum_version']) >= 0 && version_compare($object->api_version, $export['api']['current_version']) <= 0) {
                                $cache[$table][$name] = $object;
                            }
                        }
                    }
                }
            }
            drupal_alter($export['default hook'], $cache[$table]);
            // If we acquired a lock earlier, cache the results and release the
            // lock.
            if (!empty($lock)) {
                // Cache the index.
                $index = array_keys($cache[$table]);
                cache_set('ctools_export_index:' . $table, $index, $export['default cache bin']);
                // Cache each object.
                foreach ($cache[$table] as $name => $object) {
                    cache_set('ctools_export:' . $table . ':' . $name, $object, $export['default cache bin']);
                }
                lock_release('ctools_export:' . $table);
            }
        }
    }
    return $cache[$table];
}