diff --git a/data_ui/data_ui.admin.inc b/data_ui/data_ui.admin.inc index 775e0dd..a3323e1 100644 --- a/data_ui/data_ui.admin.inc +++ b/data_ui/data_ui.admin.inc @@ -849,3 +849,31 @@ function _data_ui_alter_table($table, $field_reason) { } return FALSE; } + +/** + * Simple form to print the exported hook_views_data() code. + */ +function data_ui_views_export_form($form_state, $table) { + // Get the path to the data.views.inc file, and load it + $codepath = module_invoke('data', 'views_api'); + include_once $codepath['path'] . '/data.views.inc'; + + // Get the array from hook_views_data implemented in data + $raw_export = module_invoke('data', 'views_data'); + + // Generate the code + //@TODO: format the generated code, to be compliant with coding standards. + $raw_export = $raw_export[$table['build_info']['args'][0]->name]; + $raw_export = '$data[' . "'" . $table['build_info']['args'][0]->name . "'] = " . var_export($raw_export, true) . ";"; + $code = '$data = array();' . "\n" . $raw_export . "\n\nreturn " . '$data;'; + $lines = substr_count($code, "\n"); + + // Generate the form + $form['code'] = array( + '#type' => 'textarea', + '#title' => t('Data UI generated code for hook_views_data() implementation'), + '#default_value' => $code, + '#rows' => $lines + 1, + ); + return $form; +} diff --git a/data_ui/data_ui.module b/data_ui/data_ui.module index c2cf574..db52662 100644 --- a/data_ui/data_ui.module +++ b/data_ui/data_ui.module @@ -77,6 +77,15 @@ function data_ui_menu() { 'access arguments' => array('administer data tables'), 'type' => MENU_CALLBACK, ); + $items['admin/content/data/edit/%data_ui_table/views-export'] = array( + 'title' => 'Export views integration', + 'description' => 'Export integration code for hook_views_data().', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('data_ui_views_export_form', 4), + 'file' => 'data_ui.admin.inc', + 'access arguments' => array('administer data tables'), + 'type' => MENU_LOCAL_TASK, + ); $items['admin/content/data/revert/%data_ui_table'] = array( 'title' => 'Revert data table', 'description' => 'Administer data tables.', @@ -156,4 +165,4 @@ function data_ui_get_default_path($name) { return 'admin/content/data/view/'. $path . $name; } return ''; -} \ No newline at end of file +}