Welcome

Fresh(est) from the blog

I just read a very good article about an old man who repaired typewriters during World War II and beyond. Very recommended.

http://www.theatlantic.com/issues/97nov/type.htm

For some reason, I really like old things that aren't "useful" anymore. I have a slide rule and a typewriter on my desk next to my multi-core, Internet connected computers. I'm not so much a pack-rat, I don't think (maybe consult with my wife on that question), I just like great things, no matter when in history they were considered great.

Recent TechNotes

Pre-fill comment subject line +  

I often find it handy to make a small module for most of my Drupal project the purpose of which is to perform little tweaks on default Drupal core or other module behavior. Usually this small utility module lives in /sites/all/modules/custom/tweaks/tweaks.module or something to that effect.

Having such a module around is a quick way to tap into the power of Drupal hooks.  For example, a client requested that the subject lines of any comments be pre-filled with the node name, prefixed with "Re:".  This was easily accomplished with a quick hook_form_alter, like so:

Commonly overridden node form elements +  

In order to save some time putting print_r in the form override, here are the keys of form elements I often override.
"Menu settings" fieldset = $form['menu']
"Revision information" fieldset = $form['revision_information']
"URL Path Settings" fieldset = $form['path']
"Comment settings" fieldset = $form['comment_settings']
"Authoring information" fieldset = $form['author']
"Publishing options" fieldset = $form['options']

if the publishing options is simply unset, the node will default to unpublished. If you want nodes to always be published, do this:

Overriding forms Drupal 6 +  

I find myself needing to override a form fairly often, and I'm always having to go after the process, so I'm making a note of it here. I often need to override node edit forms in order to get rid of unneeded form elements.

My reference has been this article at lullabot.

The first thing you need is the Form ID. To find this, load the form in question in a browser, then view source. Search the source for "form_id". You should find a hidden element with "form_id" as its name, like so:

Flex Namespaces and MXML +  

This is kind of cool: if you are making a Flex app and are writing your own classes, you can make a new XML namespace for them to reference in your MXML markup.

The default mx:Application opening tag gives one namespace property:

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml/" layout="absolute">

This makes it so you can prefix the tags in the document with mx: and get all of the pre-built Flex classes, like the Panel, the Application, etc.

New Snippets


<?php
/*
* The script will print "Mar"
* See php.net/date for more formatting options
*/
$m = 3
print date('M', mktime(0,0,0,$m,1,date("Y")));
?>

$state_list = array('AL'=>"Alabama",
'AK'=>"Alaska",
'AZ'=>"Arizona",
'AR'=>"Arkansas",
'CA'=>"California",
'CO'=>"Colorado",
'CT'=>"Connecticut",
'DE'=>"Delaware",
'DC'=>"District Of Columbia",
'FL'=>"Florida",
'GA'=>"Georgia",
'HI'=>"Hawaii",
'ID'=>"Idaho",
'IL'=>"Illinois",
'IN'=>"Indiana",
'IA'=>"Iowa",

Here's a cool trick, drop this code in your views display header to show how many rows were returned by the query (be sure to use the PHP code input format):

There are currently <?php
$view = views_get_current_view();
echo $view->total_rows; ?> records displayed.

I imagine that the views_get_current_view() function can come in handy for other purposes.

This is just a handy place to write this down, I don't expect it to be useful to anybody else. I messed up a Drupal installation by extracting the Drupal base install archive in my sites/all/modules directory. My site then thought it was the wrong version of Drupal. Just removing the offending folder broke the site as Drupal couldn't find it's system and other important modules. These are the SQL queries that pointed Drupal back in the right direction.


/*
* first, remove the messed up rows from the system table on the DB:
*/


<?php
echo "Hello, world!";
?>