Drupal Views bulk export

Filed under: drupal, web development — jaydublu @ 5:06 pm

I’ve been using Drupal in earnest since the New Year, and I have to say that I wish I’d discovered it sooner. It’s by no means perfect, but I think perfection is impossible with CMS systems and it’s doing everything I need it to.

Initially I was sceptical about using the Views module - I was thinking that Views are just for people who can’t be bothered to do proper PHP, but then I got into them and discovered the power and simplicity, and I have to say my first approach to most content display challenges in Drupal now tends to use Views.

But this leads on to one of my biggest gripes about Drupal - how much of the site configuration is stashed in the database where there is little accountability or control - I much prefer having files in the filesystem where you can use Version Control.

Then I discovered bulk export which does all of that - and it makes a big difference in safe use of Views. This is how I’ve done things several times now quite successfully:

  • Carry out rapid development using the Views UI as normal.
  • Enable the Views Exporter module - this turns on the ‘bulk export’ tab under ‘tools’ in the Views admin
  • In Site Building > Views > Tools > Bulk Export, select the views that you want to export, and enter the name of the module you want to store the views code in and hit ‘export’
  • Follow the instructions on the next page to add snippets to the .info and .module files, and to create the .views_default.inc file
  • In Site Building > Views > Tools > Basic, click ‘Clear Views Cache’ button
  • The right hand-most link against the views you exported in the admin list should now have changed from ‘delete’ to ‘revert’ - go ahead and ‘revert’ all the views you exported

That’s it - simples!

If you need to make any changes to exported Views, there are two approaches:

  1. Modify the exported php directly in the .views_default.inc file - these changes should be immediately reflected on the site, but you might need to hit ‘Clear Views Cache’ just to be sure.
  2. Use the Views UI, and re-export the views again, save the updated .views_default.inc file, then hit ‘revert’ on the list to use the file version

I’ve found it very useful when there are two or more enviornments being used for development (e.g. dev and live) to be able to spot that a local change has been made to an exported view by the presense of the ‘revert’ link - using diff on exports gives you a clue to what setting changed - a bit fiddly but not as bad as trying to go through every setting the UI one at a time to spot the difference. It’s also very reassuring to have Subversion (or your vrsion control system of choice) keep all your various environments in sync.

The final trick to pass on that has made my life much simpler is proper use of names and tags in views - if all the views for your module have the same prefix to their name, and the same tag, it makes it much easier to spot them all in lists, and to select them all together when you come to re-export them - it’s very embarrassing if you miss one and a whole section disappears from the site! If you need to rename or add tags - it’s easy to spot in the exported code where they can be changed, and that’s something you can’t do through the UI.

Now if only I could get more of Drupal’s config in the filesystem this way …

Collections

Filed under: life — jaydublu @ 7:22 pm

So here’s the thing - I heard some Lou Reed on TV last night and I realised I hadn’t heard Transformer for far too long, so this afternoon I decided to finally get around to digging out and plugging all the various bits of my good-old-fashioned analogue hi-fi together again after far too long.

Having got over that fact I seem to have mislaid Lou Reed, the first album that caught my eye from my cherished vinyl collection as I scanned for something to put on was Fairground Attraction “The first of a million kisses”.

So I breath a deep contented breath, close my eyes, lean back in the chair and wonder why the hell it is that I haven’t done this for … probaly a good 10 years!!! My mind wanders further, and I realise that I’ve had this album for almost two decades, and although a few tracks on side one are like old friends I don’t know if I played the whole album more than a couple of times, but it’s great. So what other gems are in the modest collection of 200 odd LPs that I once put so much thought into? Given that most of the music is probably more than 20 years old - what have I missed in the mean time? Yikes - there can’t be enough hours in the day to find out what I’ve missed or am missing!!!!

But then I realise I have the same thought when I browse through my boxes of old novels looking for the next book to read again, and discover an old favourite, or something I once bought and never got around to reading, and also when I look for a film to watch out of the DVD collection (at least I finally threw all the videos away after they went mouldy or I’d have them to worry about too).

Half way through side2 (oh how I love vinyl - so tactile!) and I’ve decided that I don’t care. In all the various collections I have squirreled about in cupboards or sheds, on shelves and in boxes (and don’t get me started on tools, or bits of electronics) I’ve got more than enough to keep me fully occupied and amused for the rest of my life even if I worked at it full time - what does it matter if I’m missing other stuff - what I’ve got already is more than I will ever need and it’s all just fantastic even if it is often more than 20 years old!

As I mellow with time, it seems I’m becoming content with what I have - the grass is pretty green over here so why worry about the other side of the bridge?

I love vinyl!