Skip to content

Instantly share code, notes, and snippets.

Munge a form field into a multiple select (and back!)

This is a sample Drupal module that modifies an existing form field to display it as a multiple select without having to modify the handling code. As far as the form's "owner" is concerned, the user enters a comma-separated list of values.

The goal is, as you can probably tell from the $form_id, to turn a profile field into a multiple select of values from elsewhere. This is probably less than ideal, but I can't figure out a better way to achieve this.

@thsutton
thsutton / .gitignore
Created October 26, 2010 13:34
An example Snap Framework web-app which displays data from a PostgreSQL database accessed with Takusen.
.DS_Store
._*
/dist/
*.log
@thsutton
thsutton / custom-breadcrumbs-pathauto.patch
Created October 28, 2010 06:08
Handle <pathauto> more usefully in custom_breadcrumbs 1.5
This patch applied to Custom Breadcrumbs 1.5 and affects the way it processes
breadcrumb links when the user specifices `<pathauto>`: rather than cleaning
the whole path with *pathauto* (and thus killing any slashes), it passes *each
component* through.
Note that this is a bit of a hack: a robust implementation would clean the
substituted values as the path is being built. As it stands any `/`s in the
substituted values will remain in the output.
diff --git a/htdocs/sites/all/modules/contrib/custom_breadcrumbs/custom_breadcrumbs.module b/htdocs/sites/all/modules/contrib/custom_breadcrumbs/custom_breadcrumbs.module
<?php
/** @file
*
* Allow users to save their progress and resume forms.
*
* @author Thomas Sutton <me@thomas-sutton.id.au>
* @copyright Bouncing Orange
* @created 2010-11-01
*/
Multiple Step Forms
===================
This module implements a techniques that can make your Drupal forms easier to
implement and easier to use: [breaking a form into multiple steps][1].
[1]: http://www.appnovation.com/create-multiple-step-form-drupal-6
@thsutton
thsutton / enumerator-filter.hs
Created December 15, 2010 09:42
A first attempt at making an enumeratee equivalent to the filter function for lists.
import Prelude hiding (sequence, map, head, filter)
import Control.Monad.Trans (lift, MonadIO, liftIO)
import Data.Enumerator
-- | Enumerator analogue of 'Data.List.filter'.
filter :: Monad m => (a -> Bool) -> Enumeratee a a m b
filter pred (Continue k) = do
x <- head
case x of
project="$0"
if [ -z "$project" ]; then
project="project"
fi
mkdir "$project"
cd "$project"
# Create the new cabal-dev sandbox and install snap
cabal-dev install snap
@thsutton
thsutton / README.md
Created December 31, 2010 12:40
Example of looping in Heist templates

Looping tags in Heist templates

This is a small example demonstrating how to implement looping template tags ("splices") with the Heist template system that is the default with the Snap Framework.

The src/Site.hs file contains the interesting bits:

  • The loop handler which simply renders the [loop.tpl
import Data.ByteString (ByteString)
import qualified Data.ByteString.Char8 as C (pack, unpack)
import qualified Data.ByteString.Lazy as L (fromChunks)
import qualified Data.ByteString.Lazy.Char8 as LC (pack)
import Data.Digest.Pure.SHA (hmacSha1, showDigest)
import Data.List (sort)
import Network.URL (URL(..), importURL, exportURL, exportParams, add_param)
-- | Calculate the SHA-1 HMAC of the parameters and include it as the parameter "h".
signParameters :: ByteString -- | The key for HMAC.
# modules/apache/manifests/init.pp
#
# Configure and manage Apache (in the Debian manner).
#
class apache {
# Configuration that might need to be tweaked.
$apache2_mods = "/etc/apache2/mods"
$apache2_sites = "/etc/apache2/sites"