Drupal code

  • Dynamic forms in Drupal 7

    When building forms, you will often want to only provide certain options if other options are chosen by a user. For example, there's no need to show the 'open link in new window' checkbox, if the 'make this into a link' checkbox hasn't been ticked. These kinds of dynamic forms haven't been easily available for Drupal... until now, with the #states for form elements in Drupal 7.

    Take a peek at this example of dynamic forms in Drupal 7.

    To make one form element be dependent on another element, you may have delved into AJAX, or tried using CTools for form item dependency. Doing it with AJAX isn't simple, and using CTools isn't always an option and includes various caveats. Now, you can make dynamic froms in Drupal 7, straight 'out of the box'!

  • Drupal roles : Programatically Adding a role to a user in Drupal 7

    It used to be a bit of a chore to add a role a user in Drupal, but no longer!

    All you need to do is this (in Drupal 7):

  • Certified to Rock field

    Certified to Rock is a site that allows you to look-up Drupal.org user names, and see their 'certified to rock' score.

    CertifiedToRock.com is a way that community members and employers can get a sense of someone's involvement with the Drupal project. The site uses a custom algorithm that gathers publicly available information which is then distilled down into a score on a scale from one to eleven.

  • Email Logging in Drupal

    There are a number of scenarios where you might want to log email being sent by Drupal; perhaps locally during development or for urgent debugging on a live site. There are a number of options available for Drupal email logging, and this article will cover four of the most common ways:

  • Using CTools for form item dependency / visibility

    What are CTools Dependencies?

    One of several helpers included in the ctools module, ctools dependency is described on the module page itself as "a simple form widget to make form items appear and disappear based upon the selections in another item". It's designed to make it easy and quick to hide/show form elements based on the value of other form elements in the browser using javascript.

  • Getting Aegir to provision a lot of sites

    There may be better ways to do this, but suppose you want to get Aegir to provision a lot of sites, maybe from a list you've got in CSV file, then you can now use Feeds!

    The Aegir feeds module exposes the key details to feeds, so that it can create site nodes. Whip yourself up a feed importer preset with the source of your choice, create site nodes and map your values to the servers and install profile that you want Aegir to use. Simples.

  • Views data exports

    Views is the king in Drupal land when it comes to making lists of your data, rightly so, it does a wonderful job of making it easy to choose the data you want to list. It also allows you to render your list in various forms, lists, tables. RSS feeds or even jump menus. So if you want to make a list and render it as CSV or XML, then you naturally turn to views, and find that currently you really have two options:

  • Facebook like views integration

    Facebook is rapidly taking over the planet, and Drupal is arguably trying to do the same. Facebook added the concept of 'liking' a webpage to their array of social tools a while ago. Drupal modules quickly added the ability to 'like' content on your site.

    This is all well and good, but what about getting some of that data back into Drupal?

    Suppose that you have an image gallery, and you want people to be able to rate the images, by 'liking' them using Facebook like. What you'd really like to be able to do then is build a 'top rated' view of those images.

  • Removing that pesky trailing slash

    So, it's perfectly valid to visit a site using a URL like:

    http://www.google.co.uk///////////

    But some pesky SEO types will complain that the site is accessible at two URLs and that you need do a 301 redirect to the canonical URL (http://www.google.co.uk/). What you want to do is remove the trailing slashes using mod rewrite.

    If you really need to do this, then you can just pop the following in the .htaccess file that Drupal provides:

  • Aegir HTTP basic authentication

    Aegir is a system for managing sites using Drupal and drush. We use it to manage this site in fact.

    However, we use a fairly old version. As a precursor to doing some more work on the backup management I wanted to get my head around the new version of Aegir, and the object orientedness.

    There's a really useful tutorial over on the Aegir community site:
    http://community.aegirproject.org/node/75
    That shows you how to add options to Aegir sites and pass the information into the backend.

    The tutorial mentions a possible real life use of implementing HTTP basic authentication on a site. Well, in an effort to understand Aegir more, I've coded it up, and you can now really easily specify HTTP basic authentication credentials for any site managed in Aegir. This is really useful for staging sites that you need to give clients access to, but don't want the entire world seeing.

Pages

Subscribe to our RSS feed Subscribe to Drupal code