Drupaler.co.za

Drupaler.co.za is part of the Perceptum Thought Squad

Drupal is a free software package that traditionally allows an individual or a community of users to easily publish, manage and organize a wide variety of content on a website. Tens of thousands of people and organizations are already using Drupal to power scores of different web sites.

At Perceptum Thought Squad, we harness the potential that Drupal offers as a community developed Web Application Framework. Using Drupal as a base, we rapidly develop back-office applications, system integration layers and work-flow systems. Using Drupal this way means that we spend less time developing repetitive subsystems (like user management, theme and template systems, etc) and more focus is given to the core business features of your application.

For contact details and more information on Perceptum, please visit our company site @ http://www.perceptum.biz/.

Drush Presentation

This is a presentation I gave at the Cape Town Drupal Meet-up.

Drupal Behaviors - What I have learned so far

"Behaviors" provides is a framework for doing jQuery in a consistent way. Its particularly cool at making sure that you dont have a lot of "document.onLoad()" js calls in theme files. Ideally what we are trying to avoid is ANY <script> tags inside our theme files. We want to decouple the JS <scripts> from the HTML (tpl.php) output.

jQuery and views_embed_view. An awesome pair.

Here is a snippet showing how to fetch a view, passing some arguments, and returning the view over jQuery to a jQuery ajax fetcher and handler.

This is assuming there is some menu entry that calls this page.


function sc_networks_membership_list_page($account_id,$group_id) {
$return = array();

$group = node_load($group_id);
$viewName = 'sc_network_members_list'; // This is the view name

// NULL can also be the name of a particular view display
// All arguments after the view display (NULL) are passed to the view as arguments

Creating an organic group programmatically

Here is a snippet we are using to create organic group nodes programmatically. It assumes you have a module called "sc_networks" in which the function will reside.


function sc_networks_enrollments_create($title = null, $description = null, $owner_name = null, $uid = null) {

# Adapted from ideas
# @ http://www.manumilou.com/blog/creating-node-programmatically

// This is needed to load the node functions
module_load_include('inc', 'node', 'node.pages');

$node = new stdClass();

Bug in CaseTracker shipped with openatrium (1-0-beta3-2)

The old version of Open Atrium (version: atrium-1-0-beta3-2) shipped with a casetracker version that has a bug in the view filter. If you added cases to the a project, and tried to filter the resulting view by "Assigned to:", the wrong users assignations would be shown.

This resulted from a call to array_splice in the casetracker.module file that was loosing the user_id => user_name indexing. The casetracker developers have rewritten that function, but upgrading our version of atrium is not trivial because of the custom stuff we have done to it.

JavaScript IE error - Expected identifies, string or number

So, you are getting an "Expected identifies, string or number" in Internet Explorer eh? Lucky you... I got this too. Debugging JavaScript in Internet Explorer is possibly one of the most frustrating experiences of my life. Starting to debug JS in IE is soul destroying. I liken it to undertaking the study of a Zen Koan. Mu.

Anyway - enough ranting. I found out what was causing this error, at least in my code.

In PHP the following array structure is quite common...

$test = array(
   'somekey' => 'somevalue',
   'someotherkey' => 'someothervalue',
);

Drush VIMRC key mapping

I've switched to using VIM as the primary PHP editor.

Integrating with Drush is a very cool way to have auto test environments. Below is a snippet from my .vimrc for automatically running drush coder on the current module, running the current fil through php lint as well as executing the current file. (Drush coder will check your module for Drupal compliance)


if !exists("autocommands_loaded")
let autocommands_loaded = 1
autocmd FileType php noremap :w!:!/usr/bin/php %
autocmd FileType php noremap :!/usr/bin/php -l %

More links we used to make our VIM cool and .vimrc file

Here are a bunch more links we found to make VIM cool. Some of this will be repeats... dont blame us. We warned you! ;) There is also a copy of the VIMRC file I am using. Its not that fancy... but it will be good to have it somewhere central for when I move it to every server I work on - ever.

http://phpslacker.com/2009/02/05/vim-tips-for-php-programmers/

http://www.vim.org/scripts/script.php?script_id=1075

http://weierophinney.net/matthew/archives/164-Vim-Productivity-Tips-for-...

http://weierophinney.net/matthew/archives/134-exuberant-ctags-with-PHP-i...

MacPorts patch for ctags-5.8 php.c

Ive spent a fair amount of time setting up VIM for my mac tonight. I had been using netbeans, but it gets frustratingly sluggish after a few hours. Having come from a generally *nix background, I decided to finally figure out how to set vim up on my MacBook.

Id previously installed VIM using MacPorts, and that relied on the ctags package which was subsequently installed as well. Version 5.8 as it were.

Drupal Twitter module causes 500 Internal Server Error

This is just a quick heads up if you are using the twitter module.

Our server cron process has been picking up 500 Internal Server Errors all week, and spamming the hell out of our Assembla ticketing account. As fun as it is getting 400 mails a day from the server, I eventually relented to trying to find the cause, and a solution.

Running the cron by hand wasnt causing the error often enough, so I created a quick shell script to run the cron in quick succession...

#!/bin/bash
while [ 1 ]
do
drush cron
echo $? is the return
done

Getting comment_notify to cc a watcher or admin account

Ok - so it has been a while since we added a hack to the drupaler.co.za collection. With exams and a few concurrent projects - blogging had to take a back seat. But with that out the way - and the light shining at the end of the 2009 tunnel, we thought we'd share today's Drupal hack with you.

The comment notify module (http://drupal.org/projects/comment_notify) is great for getting conversations going around your drupal content. It will basically inform the author of any comments to his content, as well as giving anonymous and registered users the option of being informed about comments to their comments. Pretty nifty!!

However, a use case arises where you might want any of those notifications to also be cc'd to some global administrator or to kick off some back-office process. Using Drupal's trust hook_mail_alter hook - its a piece of pudding!

First you need a custom module that you can add the hack to. If you dont have this - there are plenty of examples on http://drupal.org/ on how to create one... so we wont reinvent the wheel here. Once you have your custom module ready simply add this function to the .module file (or whatever php file you include()).

function MYMODULE_mail_alter(&$message) {
        if($message['id'] != "comment_notify_comment_notify_mail") return;

        $touser = user_load(array("mail"=>$message["to"]));
        if(!$touser || $touser->uid <= 0) return;

        $message['headers']['cc'] = "ccaddress@example.com";
}

Loading the $touser ensures that you only get cc'd on messages that are sent to registered users - and not all the anonymous posters you may have. This can be further refined to do other more complex checking to avoid duplicated ... but you get the idea, right?? Great!

Hope this helps someone do good Drupal things!

Setting the from address when calling the messaging module.

Luckily - its doesn't seem to be clearly specified how to set the sender address when manually sending messages using the messaging api module (http://drupal.org/project/messaging). This is a quick code example on how to set it for 'mail' based messaging modules.

Assuming $template is a messaging template that you have set up and filled...


$message = array();
$message['subject'] = $template['subject'];
$message['body']['header'] = $template['header'];
$message['body']['content'] = $template['main'];
$message['body']['footer'] = $template['footer'];

Manually attaching files to messages in Drupal using messaging_phpmailer

It turns out that attaching files to outbound messages is really easy if you use the messaging module (http://drupal.org/project/messaging) along with the messaging_phpmailer module.

Git branch basic confusion

I have been using Git as a version control system on some of my more recent projects. Its really powerful and pretty diverse in how it can be used.

Something that tripped me up a bit is how new files can be made visible in branches. I thought Id write it down here in an attempt to solidify the process in my mind.

Lets say you have a repository and you are on the master...

git checkout -b experimental will checkout your master to a new branch...

Syndicate content