Blog

Creating Custom Formatters with Display Suite

Here at EchoDitto, we've been making heavy use of the Display Suite module. It obliterates a lot of the more tedious theming issues we typically run into when building out a Drupal site, and for the most part, we love it. But as with any solution that takes logic out of code and puts it into the UI, if you want to do anything that isn't already provided by DS, you're going to have a write a bunch of code.

So far, the biggest drawback to using DS that we've experienced so far is the lack of formatters.

Never touch your local /etc/hosts file in OS X again

In each of my posts on setting up a local development environment on OS X, it's mentioned that you need to add your website's domain, even though it's local, in your /etc/hosts file. My preferred way to edit the hosts file on OS X is using Gas Mask. If you wanted to create the local virtual host projectx.dev, you would add the line 127.0.0.1 projectx.dev in /etc/hosts or with Gas Mask, and then use that same value in either ServerName in Apache or server_name in Nginx. This can be tedious for adding new sites. Luckily there's a way to set this up once and then never have to edit your hosts file again for adding new local virtual hosts.

Redirect all port 80 requests to port 8080

Alan Ivey's picture

In my previous post, I walked through how to set up a local environment using Nginx running on port 8080 so as to avoid running anything as root or with sudo. Something that I've found incredibly annoying is when I forget to specify the port I get an error in my browser, or Chrome might even suggest something based on a search term. It's fairly easy though to configure Apache to route everything to another port.

OS X 10.7 Lion Development: Nginx, PHP, MariaDB with Homebrew

Nginx is quickly becoming a popular, low resource alternative to Apache for many websites. This doesn't come without challenges, such as using PHP as CGI due to not having mod_php available. Nginx also does not use any Apache configuration rules, nor does it use .htaccess or anything like it, so it requires additional configuration regardless of the web application being deployed. A big help in getting Nginx started with Drupal is António P. P. Almeida's drupal-with-nginx configuration, which makes it fairly simple to deploy in Linux. But what about local development on OS X? Read on to learn get all of the required components set up for your system, as well as the modifications necessary to get drupal-with-nginx set up on OS X.

Video Thumbnails with Media and YouTube or Vimeo in Drupal 7

Paul Venuti's picture

Today, one of the designers I work with asked me a pretty simple question about a Views-based list of videos. The listing displays thumbnails of videos being pulled from YouTube and Viemo. The question was: how do I change the size of the thumbnails?

It's easy enough to change the size of images, but the process gets fairly confusing when it comes to other content types. Here's a quick breakdown of the steps I took to enable video thumbnail resizing:

  1. Create an image style.
  2. Set the effect you want on the image style.
  3. Create a file style.

Testing Asynchronous JavaScript Drupal Apps with QUnit

Ethan's picture

As one blogger has put it: “we cannot avoid testing javascript anymore”…especially when it comes to testing sophisticated client-side web apps that integrate with our servers via various APIs. As we begin to build more complex interactive functionality and web applications, making sure that our JS code is working correctly becomes central to our QA process. Tools like Drupal’s SimpleTest implementation are great for unit testing our server-side code and basic input-output expectations, but effective testing of advanced client-side functionality requires a robust, fast, JavaScript based solution.

Following up on our recent post introducing the Backbone module for Drupal, this post will cover how to test Drupal JS apps using the QUnit module. We’ve chosen QUnit in large part because its GPL lisence makes it a good fit for Drupal development, and the QUnit module is a mature, well designed implementation.

Introducing the Backbone Module for Drupal

I am tremendously, overwhelmingly, and kind of absurdly excited to announce the alpha release of the new Backbone module for Drupal. Why? Because the oddball combination of new-kid-on-the-block Backbone with venerable-ol'-stallwart CMS Drupal is actually a suprisingly well matched and powerful one.

With Backbone.js, Drupal is no longer a drag when making dynamic, JS-based functionality...in fact, it's kind of awesome. Backbone works by creating lightweight model objects in the browser that are then easily bound to the vast array of interaction events and views using a flexible client-side templating system. Drupal is a great tool for producing the sort of structured JSON data that Backbone consumes: we get the full power of Drupal's Field API and content administration tools on the server side, but don't have to deal (much) with Drupal's theme layer and rendering stack, getting Backbone's lightweight awesomeness in our UI code. It's kind of a marriage made in web development heaven.

The Backbone module for Drupal provides a foundation for building Backbone apps within Drupal sites. Following the Backbone philosophy, it extends Backbone's Model, Collection and View objects to work with Drupal nodes, views and templates, respectively, via the Services module's REST server functionality. While a few default views and example templates are also included, the rest is left up you, the developer, to build on as you please.

EJS Views Helpers With Backbone-Rails

Tyler Renelle's picture

Backbone-Rails is a useful gem for setting up Backbone.js in your Rails 3.1 app by providing all the necessary javascript files & dependencies (easy future upgrades with bundler), as well as some generators to setup your MVC directory structure. It uses EJS (Embedded JavaScript, part of Underscore.js I believe) as it's default javascript templating language and installs the ruby-ejs gem as a dependency.

Node.js and NPM on CentOS

Alan Ivey's picture

The preferred way to install node and NPM seems to be installing from source, but I'm a perennial fan of using packages to keep things tidy, especially if I need to uninstall something. I started by going to the Node.js download page, and through to Installing with a package manager. I installed the yum release RPM for the tchol.org repository as directed and installed nodejs and npm with yum. From there, I ran into two problems but thankfully they were fairly easy to resolve.

Getting Ahead of Drupal's Coding Standards w/ Drupal Code Sniffer, Vim and a little Regex

Ethan's picture

If you've submitted a project for consideration in a Drupal.org project application or issue queue, you may have received a review that looks something like this, a seemigly-endless stream of errors relating to whitespace in comments, function argument documentation format, and horribly malformed "else" statements. We can thank Drupal Code Sniffer and it's web-service offspring, the Automated project review tool at ventral.org, for much of this turn toward strict compliance reviewing. While we all know that it's "the right way to go", it can often be quite discouraging to hvae to churn through a list of what feels like miniscule issues in order to share code with the community, especially when many of those issues are caused by inconsistencies between standard code editor templates, documentation auto-generators, and what Drupal.org requires.

The good news, though, is that we can get one step ahead of the review process, and integrate these new tools into our development environment to ensure that the code we write for Drupal is alway 100% compiant, from the start.

Print Search Box Form in Template Theme File, Drupal 7

Jeremy John's picture

Neither $search_form nor $search_box is available in Zen or, likely, any other themes in Drupal 7. Instead, there's a block.

If you need to print the search box in page.tpl.php, you'll need to render the block and then print it like so:

 
block = module_invoke('search', 'block_view', 'form');
print render($block);

To break that down, 'search' is the module invoking the block. 'block_view' is the operation we want to call, that is, we want to view the block, and 'form' is the machine name of the block you want to print.

OS X 10.7 Lion Development: MacPorts

OS X Lion comes with most of the tools you would need to do "MAMP" (Mac OS X, Apache, MySQL/MariaDB, PHP) development, as outlined in my previous posts once you add a database. So then why would you want to use MacPorts? Setting your development environment up in MacPorts isolates the binaries, libraries, and configuration files, completely separate from the existing OS X install (with the exception of startup scripts). You can also tweak the configuration files on your own, apply your own patches, and apply updates that MacPorts may get before Apple pushes them. It will take more time because you'll be compiling everything, but you have all of the control. Read on for how to get things set up.

Mixing Context and Drupal's Native Block Ordering System

Paul Venuti's picture

I work on a lot of legacy sites that were built without the Context module, and I would say that at least once on each of these legacy sites, I turn to Context when I have a very specific problem: the visibility settings for a particular block are so complex that (in Drupal 6 at least) they can only be expressed by writing code. For instance: suppose you're using Organic Groups, and you want to show or hide a block based on whether the user is a member of that group.

OS X 10.7 Lion Development: Native Apache & PHP with Homebrew MySQL or MariaDB

OS X Lion ships with Apache and PHP, which both require a little bit of tweaking to get fully-functional for "MAMP" local development. The one thing Lion does not ship with is a database. This will be very similar to my previous post on local development but this time we'll be using Homebrew to install either MySQL or MariaDB for the database. Since we'll be using a compiler for Homebrew, I'll also cover how to add APC and other PECL modules that you can add to OS X.

OS X 10.7 Lion Development: Native MAMP with MySQL installer

Alan Ivey's picture

With the release of Lion, there are some subtle differences to setting up a local MAMP (Mac OS X, Apache, MySQL, PHP) environment compared to Snow Leopard. In an effort to keep this from being overly wordy and just get to the good stuff, we'll dive right in, so read on to get started.

Use Syslog instead of Watchdog

Alan Ivey's picture

It seems to be standard for Drupal, at least in version 6, that Watchdog is enabled and used to write errors/warnings/notices to the watchdog table in the database. Depending on the verbosity of your PHP output, amount of 404s, or other information that would be going into this log, it could mean a lot of writes on your database. While you should trace errors/warnings and solve them, sometimes you may want this increased information for debugging. If your site receives a lot of traffic, this could mean decreased database performance. A solution to this is to instead utilize the core Syslog module instead of Watchdog. Here's how I got it set up in Drupal 6 on CentOS 5 servers.

Views Search by Link Module's URL Title: More Views Hacking

Jeremy John's picture

So recently I wanted to filter by URL title, having used it extensively as a text field with an optional link in a site.

The code below is supposed to apply to an exposed Link module field filter in Views. Instead of searching to see if the search string matches the URL, this will match the URL title that was provided.

In the code below, you would replace node_data_{field_publication_author.field_publication_author} with the name of your field, in all places that "field_publication_author" occurs in the below.

Removing Behaviors Using a GMap Macro

Paul Venuti's picture

I'm building some maps for a client using the GMap module and came across the following simple problem: using a GMap macro, how do you remove a default attribute?

The GMap module lets you set a number of default attributes for your maps: width, height, center position, initial zoom, and so on. If you want to change any of the default settings for a given map, you need to specify your overrides in a GMap macro, which looks something like this:

[gmap zoom=3| width=500px |height=350px]

It's all simple enough until you get to the behaviors.

Preventing empty CCK-based blocks from printing

Paul Venuti's picture

Today I learned that if you have a Views-powered block that uses CCK fields; and the CCK fields are empty for all the returned rows; then Views doesn't realize you've got an empty set and it still prints all the scaffolding for your block – the admin links, the container divs, and so on. The content of the block is empty, but the HTML still takes up space and throws off your layout.

Fixing this is easy. To prevent an empty CCK field-based Views-powered block from being output, add a filter on the CCK field and set the filter to Is not empty (NOT NULL).