PHP

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:

Number to Month 1  


<?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")));
?>

+

PHP State array +  

$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",

Drupal Views count results 2  

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.

Hello world PHP style +  


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

+