Since Table Wizard has been deprecated in favor of Data, is it possible to export Views integration, the way you could with Table Wizard? In the past, I've used Table Wizard to export the Views integration code (ie, hook_views_data). I usually then disable the Table Wizard module and create the views my module needs manually.

In short, does the Data UI module have something along the lines of Table Wizard's "Export views definitions for selected tables" button?

Comments

jedihe’s picture

Title: can data export views integration? » Export views integration (patch)
Component: Documentation » Code
Status: Active » Needs review
FileSize
1.92 KB

I've added a fairly simple export of views integration, attached is a patch against 1.0-alpha14.

I compared the output for both Table Wizard and Data (with this patch applied) and they seem different; don't know why they are different, but Views allowed me to create a view of a test table exposed by data without problem.

Matt V.’s picture

I had trouble getting the patch to apply cleanly, but I was able to manually apply the changes. I was then able to export the hook_views_data code and build a view of my table's data. Thanks a lot!!!

For what it's worth, I tried git apply 1074156_views_export.patch and patch < 1074156_views_export.patch from the root of the data module directory and got errors with both. The git apply returned:

...
error: data_ui.admin.inc: No such file or directory
error: data_ui.module: No such file or directory
...

And patch returned:

...
Hunk #1 FAILED at 1027.
...
Hunk #1 FAILED at 135.
...

Any idea what I was doing wrong?

jedihe’s picture

The patch was created using the --no-prefix option, to make it work nicely with drush make. I think the way to apply it is by using patch -p0 (though I'm not really sure of it).

Georgii’s picture

jedihe, thanks for the patch! It's nice to see that this module is not dead and is being worked on!

Matt V.’s picture

Status: Needs review » Reviewed & tested by the community

@jedihe Thanks! Using patch -p0 < 1074156_views_export.patch made the patch apply cleanly.

Thanks again for a great addition to the module.

jedihe’s picture

Posted this in stackexchange, and I think it can be of use to someone looking at this issue.

This is a summary of the steps to easily get views integration with an external database by leveraging Data (Drupal 6):

1. Installed Data module with the patch in #1.
2. Created a stub structure of the tables I needed inside the Drupal database using Data.
3. Used phpmyadmin to dump the SQL code for creating the tables in a separate DB.
4. Copied the hook_views_data() export provided by the patched Data module into mymodule_views_data() hook (in mymodule.views.inc; it requires to define hook_views_api in mymodule.module). Notice the export code is provided per-table, you must copy it one by one and perform a few tweaks to the code.
5. Decided which table to use as base and only left that one with the 'base' entry for the 'table' part of the views integration definition in hook_views_data().
6. Added db_url['mydb'] entry to settings.php (remember to add 'default' key for the Drupal DB).
7. Added the key 'database' to the views definition for the base table, with value 'mydb' (see 6).
8. Remember to delete the stub tables definition from Data module.

And that's it, I didn't have to pollute the main Drupal DB and views got to offer me all its power :)

I highly recommend checking out the views documentation (install advanced_help) along with the steps I described to get the entire picture; I decided not to write a too detailed explanation to keep the general idea clear and simple.

joachim’s picture

Category: support » feature
Status: Reviewed & tested by the community » Needs work

Could this not be done with Features?

jedihe’s picture

AFAIK, Features doesn't create the hook_views_data() implementation required for getting views to work with external databases; Features purpose is to capture configuration and put it into code, as a way to solve the dev/stage/production problem.

joachim’s picture

Ah, I get it now -- this exports hook_views_data, whereas Features exports hook_views_default_views.

Technically, exporting views data *could* be added to Views though... ;) But it might be a bit of a stretch of what Features is meant for.

Patch needs a bit of cleaning up for whitespace and documentation:

+++ data_ui/data_ui.admin.inc
@@ -1027,3 +1027,27 @@ function _data_ui_get_join($join, $field) {
+function data_ui_views_export_form(&$form_state, $table) {

No function docblock.

+++ data_ui/data_ui.admin.inc
@@ -1027,3 +1027,27 @@ function _data_ui_get_join($join, $field) {
+  // Get the array from hook_views_data implemented in data  ¶

Comments should end with a full stop.

jedihe’s picture

Version: 6.x-1.0-alpha14 » 6.x-1.0
Status: Needs work » Reviewed & tested by the community
FileSize
2.09 KB

Updated the patch with the indicated fixes, added a TODO for coding standards compliance of the exported code and created it from 6.x-1.0.

It should apply cleanly using patch -p0 < 1074156_b_views_export.patch

joachim’s picture

Status: Reviewed & tested by the community » Needs review

This should get a review from someone else.

joachim’s picture

Version: 6.x-1.0 » 7.x-1.x-dev
Status: Needs review » Needs work

And now the main branch is 7, this should be committed there first then backported.

msti’s picture

#10 works with 6.x-1.1

msti’s picture

Status: Needs work » Needs review
FileSize
3.64 KB

Here is the patch for 7.x
Please review

sh radhoush’s picture

actualy the patch does not do enyting in drupal 7.38!!

jedihe’s picture

Issue summary: View changes
FileSize
2.32 KB

EDIT: did it wrong, see next comment.

Rerolled patch from msti (#14); trying to get it to apply on current 7.x-1.x.

jedihe’s picture

Rerolled patch from msti (#14); trying to get it to apply on current 7.x-1.x.

Update: Patch applies, but couldn't test it. Simplytest.me is spawning a D6 site for some reason (data.info has "core = 7.x", so no issue there).