You are here

function ctools_get_default_object in Chaos Tool Suite (ctools) 7

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

Get the default version of an object, if it exists.

This function doesn't care if an object is in the database or not and does not check. This means that export_type could appear to be incorrect, because a version could exist in the database. However, it's not incorrect for this function as it is *only* used for the default in code version.

File

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

Code

function ctools_get_default_object($table, $name) {
  $schema = ctools_export_get_schema($table);
  $export = $schema['export'];
  if (!$export['default hook']) {
    return;
  }

  // Try to load individually from cache if this cache is enabled.
  if (!empty($export['cache defaults'])) {
    $defaults = _ctools_export_get_some_defaults($table, $export, array(
      $name,
    ));
  }
  else {
    $defaults = _ctools_export_get_defaults($table, $export);
  }
  $status = variable_get($export['status'], array());
  if (!isset($defaults[$name])) {
    return;
  }
  $object = $defaults[$name];

  // Determine if default object is enabled or disabled.
  if (isset($status[$object->{$export['key']}])) {
    $object->disabled = $status[$object->{$export['key']}];
  }
  $object->{$export['export type string']} = t('Default');
  $object->export_type = EXPORT_IN_CODE;
  $object->in_code_only = TRUE;
  return $object;
}