Virtual host, hosts file, downloading and enabling modules and installing Drupal in one line.

Tue May. 8 2012

Woah, that's a long title.
So, just wanted to share the little shell script I use for setting up local development sites in a one-liner in the terminal. Be advised that I don't usually write shell scripts, so if you are a pro, and I have made some obvious mistakes, please feel free to give improvements in the comment section. Also, while i have been writing this post, i noticed that Klausi also has a kick ass tutorial and shell script on his blog. Be sure to read that as well, since the article is much more thorough than mine. But since my script is for those even more lazy, I decided to post it anyway.
The idea I had was pretty simple. I constantly have the need to set up a fresh, working copy of drupal in various versions with various modules, i.e for bug testing, prototyping, or just testing a patch on a fresh install. While drush make and installation profiles are both awesome tools for a lot of things, I wanted to install Drupal without making make files and writing .info files, and at the same time generate the virtual host and edit my hosts file. And why not also download and enable the modules i need. For a while I used just

$ drush si

(site-install) on a specified directory for flushing and starting over, but part since I have little experience in writing shell scripts (I said that, right?), I thought, what the hey, let's give that a go. Fun to learn new stuff.
On my computer the script is called vhost, but since this is not a describing name, and the script is all about being lazy, let's call it lazy-d for the rest of the article (lazy-d for lazy drupal. Also, it is kind of catchy).

Drupal and HTTP requests - how low can you go?

Sat Feb. 25 2012

Disclaimer: This is an experiment, and would probably not apply to most websites (if any). My mission: Load my homepage in 1 HTTP request without compromising layout or functionality. Just to be clear, the motivation is not to gain any performance from this, just to see if I can do it.

So, back to the point. Drupal has a lot of css, js and image files by default. To load them all you have to ask the server to serve them to you, simple as that. So if you have to ask less times, the page would load faster. In theory. This blog has over 40 requests on the front-page, out of the box. Luckily, Drupal has a number of tools you can use to minimize requests, and among them is the optimization you can find in core. You can find it under the “performance” settings (depending on what version you are on, this is located under “configuration->development” or “site configuration”). Cool. But this still leaves me at more than 10 HTTP requests. I want less! So what next.

Creating nodes with images using phonegap and services

Sat Feb. 4 2012

A lot of different people has started experimenting with Phonegap and Drupal. You have Jeff Linwood and his Drupal plugin for Phonegap for iOS, and I just discovered Drupalgap as I was planning this post the last weeks, which does more or less (actually it does more, but not all) some of the same things I will try to do in this post.

If you want to get up and running real quick, Drupalgap seems great. If you want to learn the code behind it, and extend it yourself (this was my motivation), keep reading.

Debugging cross domain javascript

Sat Jan. 21 2012

As I have briefly mentioned in an earlier post, you can easily post to your Drupal site from a phonegap app. The reason for this is that the cross domain browser restriction does not apply for the apps you are building because it is basically a local file (the file:// protocol). While this is really swell, you don't actually develop on your phone, so it would be practical to try out all this in your browser before you deploy to your phone.

Local development without downloading the files directory

Thu Dec. 22 2011

Cloning a production site to your local development environment is super easy. Often you have it in git, or maybe even as a make file. Anyway, you just grab the code and restore the site from a backup_migrate dump. But maybe you have a KING SIZE files directory that you don’t want (or have the time) to download. Enter Apache rewrite magic!

How to enable comments on multiple nodes

Thu Dec. 1 2011

Today I had a bunch of old nodes from a migrated d6 site that did not have comments enabled, although the content type had comments enabled. This could also be the case if you have created a bunch of nodes, and all of sudden change your mind and want to enable comments on them anyway. One could always edit each one of them and turn on the comments, but that just can't be the only way, I thought, and did some research.

Why did my cached css files not load?

Mon Aug. 22 2011

I had this problem a while back, my css files that was cached and aggregated did not load. Looking at it in firebug, I realized that the files were loaded, but scrambled with bogus characters. The solution was embarrassingly simple, and was due to an error on my end. But it took me a lot of research to find out what the problem was.

How to insert a fixed string value in a feeds feed with xpath parser

Wed Aug. 3 2011

So you have a feed that you aggregate through feeds, and all new items should have the same value in a given field. For example if you have feeds from 4 different webshops, you may want to add a fixed value of the webshop description that is not present in the feed for each different feed. So how do you make a feeds feed give the same value for each feed item? If you use feeds x path parser (as I often do), how do you fix a value for each item in the feed? Or more specifically, how do you insert a fixed value with xpath?

How to find the field language in Drupal 7

Tue Aug. 2 2011

how to find the field language in drupal 7

I was writing a module which took a user defined field and did something based on the value of it. To access the field value I had to access the array which consists of field_name['language'][n]['value']. And the language can vary within a site, even within a content type. So why not take the $node->language variable, you may ask. Well, it can theoretically differ from this as well (as my thorough testing showed).

Pages