You are here

function ctools_export_default_to_hook_code in Chaos Tool Suite (ctools) 6

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

Default function to export objects to code.

Note that if your module provides a 'to hook code callback' then it will receive only $names and $name as arguments. Your module is presumed to already know the rest.

1 call to ctools_export_default_to_hook_code()
ctools_export_to_hook_code in includes/export.inc
Convert a group of objects to code based upon input and return this as a larger export.

File

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

Code

function ctools_export_default_to_hook_code($schema, $table, $names, $name) {
  $export = $schema['export'];
  $output = '';
  $objects = ctools_export_load_object($table, 'names', $names);
  if ($objects) {
    $output = "/**\n";
    $output .= " * Implements hook_{$export['default hook']}().\n";
    $output .= " */\n";
    $output .= "function " . $name . "_{$export['default hook']}() {\n";
    $output .= "  \${$export['identifier']}s = array();\n\n";
    foreach ($objects as $object) {
      $output .= ctools_export_crud_export($table, $object, '  ');
      $output .= "  \${$export['identifier']}s['" . check_plain($object->{$export}['key']) . "'] = \${$export['identifier']};\n\n";
    }
    $output .= "  return \${$export['identifier']}s;\n";
    $output .= "}\n";
  }
  return $output;
}