5 Drush Make tips and tricks
Drush make is a fantastic tool that lets us basically have a build file for each site or multi-site base instance. I pair the make file with a custom installation profile and Aegir but on its own it is a powerful tool. Drush 5 supports a few upgrades for make so it is worth upgrading if appropriate from Drush 4.
5 Tips and Tricks
1. Use http://drushmake.me/ to generate a decent base make file for new projects.
This is also a handy way to see popular modules and libraries that have somehow been beneath your radar.
2. Patch your modules with Drush.
The syntax is fairly straightforward. You can also chain patches by applying one and then applying the next.
projects[project name][patch][] = "url to patch"
For example, to patch the CAS module for using SSL/TLSv1 you would do the following: projects[cas][patch][] = "http://drupal.org/files/enforce_tlsv1_0.patch"
3. Download your custom modules via git.
To do this you need to tell Drush make to use git and then you simply provide the public repository URL.
projects[wwuzen_gsa][download][type] = "git"
projects[wwuzen_gsa][download][url] = "https://bitbucket.org/wwuweb/wwu-google-search-appliance.git"
projects[wwuzen_gsa][type] = "module"
Unlike normal make projects you download you do not need to provide a version, but you do need to state that it is a git project and provide the URL. Whatever you put in the [] after the word projects is what the directory will be created as.
4. Move sub-directories within libraries to their proper location.
Often, external libraries do not extract from a tar or zip with the file your Drupal module is looking for. It might be buried inside of a sub-directory. With Drush 5 we can move them upon the build.This is an example from the CAS library.
libraries[CAS][download][subtree] = CAS-1.3.2/
With the subtree identified, Drush make will dowload and extract the library like normal, and then move the contents of the sub-directory CAS-1.3.2 into the main directory CAS. It might take a few attempts to figure out whether you need a / in front of the directory or not but the end result is a library extracted properly.
5. Move libraries upon install anywhere you would like.
The feeds module loves to have the Simple Pie XML parser library inside of it's own module directory. What a pain. However, Drush make can move it for us.
libraries[simplepie][destination] = "sites/all/modules/feeds/libraries"
Just plop in the destination you would like to have the library moved to and the script makes it so. (Pun intended).
Zurb responsive tables within Drupal
Responsive tables are a big challenge. Tabular data is often very important and you don't want to hide the data just to keep the nice responsive design in shape. Currently within Drupal I am not aware of any defacto solutions. I experimented with jQuery Mobile's technique table reflow, the footable module, and lastly Zurb's responsive tables.
I had one criteria for a successful solution; my users should not have to do anything to make their table responsive. I did not want them to right click on the table and add a class, I didn't want them to have to build all of their tables with views, just plop in a ckEditor table and hit save.
A secondary criteria was that the solution should be lightweight since it is primarily to be used by users on mobile devices and we don't all have 4G LTE in our offices and living rooms as of yet. All of the solutions mentioned above use some sort of CSS hook to indicate that the table needs to become responsive at certain breakpoints. The lightest weight solution for me turned out to be Zurb's approach.
To automate the insertion in the HTML of a CSS class I turned to the Flexifilter module. Not enough people use this module but what it allows you to do is to create a Drupal input filter, so really an output filter, on anything that is formatted, like your WYSIWYG output.
After enabling the module you need to go to Structure -> Flexifilters -> Add New Flexifilter.
Inside of a filter you have several options but the Pattern Based Text Replacement widget works with regex. Once a filter is configured, you have to enable it. Once enabled, head over to your text format configuration screen and enable your new filter.
Configuration -> Content Authoring -> Text Formats -> Full HTML. I put the filter as the last item to be ran so that I can ensure the class I want added is actually added.
So now we have a class called responsive being added to tables folks create. How does this help us? We need to leverage Zurb's great work to answer that. You can grab the source from their GitHub project page. We want two of the files, responsive-tables.css and responsive-tables.js. You can discard the rest. Place the css file in your theme/css directory and the js file in your theme/js directory.
Open up your theme.info file and tell Drupal about these two new files. In a Zen sub-theme it looks like this:
stylesheets[all][] = css/responsive-tables.css ; Optionally add some JavaScripts to your theme. scripts[] = js/responsive-tables.js
Next, open up the responsive-tables.js file as we need to wrap it in a Drupal safe closure. At the very top of the file add
(function ($, Drupal, window, document, undefined) {
and at the very bottom add
})(jQuery, Drupal, this, this.document);
This allows the code that the Zurb folks wrote to run without conflict with the other jQuery that Drupal executes. That is pretty much it. Save those files. Go to Structure -> Appearance to reload the info file and your table should now be responsive at small window sizes.
How to include jQuery.ui effects in Drupal 7
The Task:
On a recent project I had to have a div slide to the left when a link was clicked. I thought that would be easy as Drupal 7 has the jQuery UI packaged by default. So I coded up a bit of jQuery that used a .slide() function but nothing happened when clicking the link. Looking at the FireFox JavaScript console I saw an error stating that slide was not available.
Why not?
It turns out that even though jQuery UI is shipped with Drupal none of the UI effects are turned on by default. That is a good thing as most folks, myself included, will not use many if any of the packaged enhancements.
The Solution:
Using my trusty Google skills it didn't take long to find a great post by Andy Carter detailing how to include effects from the UI library in Drupal 7. One caveat that his post and others do not explicitly state is that the system library includes the ui and the effects array. For a short while I was trying to include the slide effect like so.
drupal_add_library('system','ui.slide');
This does not work. I needed to use the effects.slide. The key is to look at what is inside of $libraries[''] and using that in your call. All of the available libraries provided by the system can be found on the system_library page.
Here is a complete example of what ended up being included in template.tpl.php.
function wwuzen_preprocess_page(&$variables, $hook) {
//Add the slide effect for our search box
drupal_add_library('system','effects.slide');
}
Notice that I use effects.slide rather than ui.slide. With that change in place my expected behavior executed properly.
Drupal Registry Rebuild
Recently on a server I was on I was getting a drush error that would not let me use drush dl, drush cc, etc... What was most frustrating is that the error was being reported about a site that doesn't even exist on the server! What to do?
require_once(/home/WWU/bronsem/cmssites/test/sites/wcedev.atus.wwu.edu/modules/entity/includes/entity.inc):[warning] failed to open stream: No such file or directory bootstrap.inc:3066 PHP Fatal error: require_once(): Failed opening required '/home/WWU/bronsem/cmssites/test/sites/wcedev.atus.wwu.edu/modules/entity/includes/entity.inc' (include_path='.:/usr/share/php5:/usr/share/php5/PEAR') in /srv/www/campusweb/cmssites/test/includes/bootstrap.inc on line 3066 Drush command terminated abnormally due to an unrecoverable error. [error] Error: require_once(): Failed opening required '/home/WWU/bronsem/cmssites/test/sites/wcedev.atus.wwu.edu/modules/entity/includes/entity.inc' (include_path='.:/usr/share/php5:/usr/share/php5/PEAR') in /srv/www/campusweb/cmssites/test/includes/bootstrap.inc, line 3066
That is a pretty gross error. When that error occurs it can be nigh impossible to get your site running. Awhile ago a colleague, Vid @ Developments, mentioned the drush rr command which is not built into drush. Go to http://drupal.org/project/registry_rebuild and get it. It is super simple, cleans up random cruft like above. Often those types of messages occur when you are removing a module from your sites/sitename/module folder when you want to use the version in sites/all/modules. If you run into errors, give drush rr a whirl.
Steps to install
- Navigate to a location where you can run drush commands. For most of us our home directory is fine.
- Type "drush dl registry_rebuild" without the quotes and hit enter. Now it is installed. You should see something like: Project registry_rebuild (7.x-1.9) downloaded to /home/WWU/bronsem/.drush/registry_rebuild. [success]
Project registry_rebuild contains 0 modules: . - Now navigate to the site that is causing you issues and run drush rr.
Supposedly you can run the command from a URL as well. That might be useful if you are on a box that doesn't allow you access to the command line. For full documentation check out the project page.
Wicked cool utility that makes drush even more awesome. Thank you omega8cc, rfay, and q0rban.
Structured Content in Drupal
A colleague sent me the link to Rachel Andrew's talk at the Smashing Conference, 2012 in Germany. The talk she gave was on the future of the CMS. I want to first say what a great talk. She hits on several key points in a style that made me think and laugh at the same time. The first third of the talk discusses structured content. Structured content is the idea that each distinct concept that we want to show users is entered by a user as a separate piece of content. Rachel uses an example of a date. Dates, locations, times, headings, sub-headings, ancillary links, etc...
I am primarily a Drupal developer these days and during the start of the talk I kept nodding my head and telling myself, Drupal can do that. While Drupal can accomplish this it can be a fairly poor user experience. Each piece of structured content is basically a form field and for a small piece of content like a blog post, there could be 5-10 fields. To solve this we can try to help the user by pre-populating the date, time, location, etc... She goes onto present three key points of what a CMS should do in the future.
- The CMS should help content editors make good decisions.
- The CMS allows the designer to make semantic decisions so the editor doesn’t have to.
- The CMS protects the design and architecture decisions made for the site.
I would like to say that a properly constructed Drupal 7 site very nearly presents the future CMS now. However, Jeff Eaton of Lullabot just published an interesting article, Inline Editing and the Cost of Leaky Abstractions. How will structured content survive inline editing?
"Structured content is not a silver bullet."
Rachel AndrewJeff's article and Rachel's talk both emphasize a careful balance. The colleague who sent me the talk and I discussed this as well and balance is the actual hard part. We can structure everything as unique fields and attach metadata behind the scenes, etc... but it then borders on insanity as you look at the form. Again we abstract some of the complexity and hide it from our user, that is part of our job but for complex data a big form is overwhelming. Big forms are nothing new and many strategies exist to solve them, and using contextual overlays we can break the forms down in Drupal into manageable chunks. This is not yet the norm.
"Avoid directly inserting HTML into content."
Rachel AndrewI applaud Rachel for discussing this topic. I do not agree that markdown is an answer, mainly because I have always had a hard time with it. I like the idea of using a WYSIWYG type entry system for users where they can highlight some text and italicize or bold a word. Not because it is familiar for users but because it is fast. However, this again comes back to a balance. If I strip all HTML or do not give a user a chance to emphasize text in anyway, I must ensure the design accounts for this. Perhaps the only bold text is the subheading for the title of the page. The only text that is italicized is the image caption. I think this is brilliant but difficult for me to achieve.
Here is to the future CMS!
Thank you Rachel for discussing the issues above. While it may be difficult for me to achieve the balance I have discussed, we all need to struggle to find answers to these issues. The web will be a better place for it.


