Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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?
Comment | File | Size | Author |
---|---|---|---|
#17 | data-views-data-export-1074156-17.patch | 2.19 KB | jedihe |
#16 | data-views-data-export-1074156-16.patch | 2.32 KB | jedihe |
#14 | export-views-integration-1074156.patch | 3.64 KB | msti |
#10 | 1074156_b_views_export.patch | 2.09 KB | jedihe |
#1 | 1074156_views_export.patch | 1.92 KB | jedihe |
Comments
Comment #1
jedihe CreditAttribution: jedihe commentedI'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.
Comment #2
Matt V. CreditAttribution: Matt V. commentedI 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
andpatch < 1074156_views_export.patch
from the root of the data module directory and got errors with both. The git apply returned:And patch returned:
Any idea what I was doing wrong?
Comment #3
jedihe CreditAttribution: jedihe commentedThe 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).
Comment #4
Georgii CreditAttribution: Georgii commentedjedihe, thanks for the patch! It's nice to see that this module is not dead and is being worked on!
Comment #5
Matt V. CreditAttribution: Matt V. commented@jedihe Thanks! Using
patch -p0 < 1074156_views_export.patch
made the patch apply cleanly.Thanks again for a great addition to the module.
Comment #6
jedihe CreditAttribution: jedihe commentedPosted 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.
Comment #7
joachim CreditAttribution: joachim commentedCould this not be done with Features?
Comment #8
jedihe CreditAttribution: jedihe commentedAFAIK, 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.
Comment #9
joachim CreditAttribution: joachim commentedAh, 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:
No function docblock.
Comments should end with a full stop.
Comment #10
jedihe CreditAttribution: jedihe commentedUpdated 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
Comment #11
joachim CreditAttribution: joachim commentedThis should get a review from someone else.
Comment #12
joachim CreditAttribution: joachim commentedAnd now the main branch is 7, this should be committed there first then backported.
Comment #13
msti#10 works with 6.x-1.1
Comment #14
mstiHere is the patch for 7.x
Please review
Comment #15
sh radhoush CreditAttribution: sh radhoush commentedactualy the patch does not do enyting in drupal 7.38!!
Comment #16
jedihe CreditAttribution: jedihe as a volunteer commentedEDIT: did it wrong, see next comment.
Rerolled patch from msti (#14); trying to get it to apply on current 7.x-1.x.Comment #17
jedihe CreditAttribution: jedihe as a volunteer commentedRerolled 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).