Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import a view from Drupal 7 #77

Open
Graham-72 opened this issue Mar 19, 2015 · 11 comments
Open

Import a view from Drupal 7 #77

Graham-72 opened this issue Mar 19, 2015 · 11 comments
Labels

Comments

@Graham-72
Copy link

Is there an automated way to import a view from Drupal 7 and create the json file needed by Backdrop?

@quicksketch
Copy link
Member

There is no built-in way to do this. Although I wouldn't completely recommend this, you could probably do the following. (Note, I haven't actually tested this.)

  • Use the Views UI to export to PHP code in D7.
  • Copy the export string.
  • Paste into a new .php file with following:
// Paste in view export here. Which defines the $view variable.
print json_encode($view);
  • Copy that JSON output into a new config file in Backdrop. e.g. views.view.[my_view_name].json
  • Clear caches.
  • The view should show up in the Views UI. Edit it and resave to update the format to match Backdrop config files.

This would also make an excellent contrib module. 😉

But in general, the configuration of a view in D7 is identical to Backdrop. You could also look at views_update_1001() for reference to see how the upgrade was done.

@Graham-72
Copy link
Author

Thanks @quicksketch . I will give it a try. I need it for the port of contrib Twitter.

@quicksketch
Copy link
Member

I need it for the port of contrib Twitter.

Oh! Well another option if this is a one-time thing:

  • Make a new D7 site.
  • Install Twitter module on the D7 site.
  • Edit each view provided by the Twitter module to "override" it so that it is in the database.
  • Point Backdrop at that D7 database and run update.php.

Now all the Twitter views are converted to JSON config files.

@Graham-72
Copy link
Author

Longer term I want to move to Backdrop a Drupal 7 site that has several custom views. Will this update procedure also be good for that?

@quicksketch
Copy link
Member

Longer term I want to move to Backdrop a Drupal 7 site that has several custom views. Will this update procedure also be good for that?

Yes! Definitely. Backdrop's update.php can update just about anything that is in the database to config files, including content types, menus, views, vocabularies, fields, image styles, etc. The only problem is that some things are stored in code in D7 and not in the database at all (like default views and image styles). So before you upgrade a site, you have to get everything back into the database (oh the irony) before you run update.php to upgrade to Backdrop.

If you've used Features in the past, https://www.drupal.org/project/unfeaturize might come in handy for this purpose. 😄

@Graham-72
Copy link
Author

Hi @quicksketch - I have successfully imported the view of tweets into the contrib module Twitter for backdrop, but the block option within the view is not appearing in the list of blocks within Backdrop. What else do I need to do? (The page view works fine).

I used your suggestion of making a D7 site and then updating that to Backdrop. It produced one alarming error report but I pressed on to try update.php and everything went well, producing the necessary config file.

@quicksketch
Copy link
Member

Hm, maybe edit the view and check to make sure that the "Block" display is set up correct and that the preview works within Views. It might not hurt to change a simple option and then re-save the view just to make sure everything is set up correctly in the config file.

@Graham-72
Copy link
Author

I was misunderstanding things and expecting the block view to be listed at admin structure : custom blocks : list blocks. But it is not there and shows up OK when going to Edit layout : Add block

However, having done this and setting that it should appear on a test page, it is not rendering correctly, so I shall investigate further, perhaps trying by creating and using a different view block.

The content is showing correctly within Views preview.

From: Nate Haug [mailto:[email protected]]
Sent: 20 March 2015 14:43
To: backdrop-ops/contrib
Cc: Graham Oliver
Subject: Re: [contrib] Import a view from Drupal 7 (#77)

Hm, maybe edit the view and check to make sure that the "Block" display is set up correct and that the preview works within Views. It might not hurt to change a simple option and then re-save the view just to make sure everything is set up correctly in the config file.


Reply to this email directly or view it on GitHub #77 (comment) .Image removed by sender.

@Graham-72
Copy link
Author

A few more tests show that my views block listing tweets is there in the system and will show correctly in certain conditions. But I am seeing something very odd happening with layouts, and interaction between blocks. At first sight it seems that blocks generated by views interact with the main page content block, causing the latter to do strange things. I must try testing more combinations.

@quicksketch
Copy link
Member

I was misunderstanding things and expecting the block view to be listed at admin structure : custom blocks : list blocks. But it is not there and shows up OK when going to Edit layout : Add block

We have an issue for displaying a list of available blocks at backdrop/backdrop-issues#449.

@docwilmot
Copy link

I'm not getting this. I want to convert the contents of a hook_views_default_views() to json. Can you please explain simply again how to do this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants