Subscribe to Syndicate

Drupal Developer and Systems Administrator

Support for your Drupal Website

Code snippets

paulbooker's picture

Create a custom template file for a custom block in drupal

//implementation of hook_block_info
function mymodule_block_info() {
  $blocks = array();
  $blocks['myblock'] = array(
    'info' => t('My Block Title'),

  return $blocks;

//implementation of hook_block_view
function mymodule_block_view($delta='') {
  $block = array();

  switch($delta) {
    case 'myblock' :
      $variables = array(); 
      $block['content'] = theme('mytemplate', $variables);
  return $block;

//implementation of hook_theme
function mymodule_theme() {
  return array(
    'mytemplate' => array(
paulbooker's picture

Updating a user role when a class (group) is flagged as finished

function mymodule_training_class_node_form_submit($form, &$form_state) {

  if ($form_state['input']['field_class_is_finished']['und'] == 1) {
    $nid = $form_state['values']['nid'];  
    $query = db_select('og_membership', 'ogm')
      ->condition('ogm.gid', $nid, '=')
      ->fields('ogm', array('etid'));				
    $result = $query->execute();
    foreach ($result as $record) {
      $uid = $record->etid;

function _mymodule_training_class_assign_alumni_role($uid){
paulbooker's picture

Updating tables and columns belonging to a custom field

  * Returns all fields created on the system of the type defined in mymodule.
function mymodule_get_mymodule_fields() {
  $types = array_keys(mymodule_field_info()); // field types defined in mymodule
  $fields = array();
  foreach (field_info_fields() as $field) {
    if (in_array($field['type'], $types)) {
      $fields[] = $field;
  return $fields;
 * Convert column(s) to double precision.
function mymodule_update_7101() {
  $fields = mymodule_get_mymodule_fields();
  foreach ($fields as $field) {
paulbooker's picture

Implementation of hook_field_schema().

 * Implements hook_field_schema().
function mymodule_field_schema($field) {
  return array(
    'columns' => array(
      'fid' => array(
        'description' => 'The {file_managed}.fid being referenced in this field.',
        'type' => 'int',
        'not null' => FALSE,
        'unsigned' => TRUE,
      'title' => array(
        'description' => "Photo title text",
        'type' => 'varchar',
        'length' => 128,
        'not null' => FALSE,
    'indexes' => array(
      'fid' => array('fid'),
paulbooker's picture

Update Script Using Batch API: Implementation hook_update_N()

 * Implements hook_update_N().
 * Removes aliases for content types that do not need them.
function mymodule_update_7002(&$sandbox) {
  // Set default patterns to empty so that aliases are not generated for every
  // node. You will need to set the pathauto pattern for every content type that
  // you do want to have a generated alias.
  variable_set('pathauto_node_pattern', '');
  // Remove existing aliases for node types: marquee, news_feed
  $types = array(
  if (!isset($sandbox['max'])) {


Shell command snippets

curl -X POST -i -H "Content-type: application/json" -c cookies.txt -X POST -d '
curl -i -H "Content-type: application/json" -b cookies.txt -X POST -d '
        "subject":"This a test comment",
        "comment_body": { "und": [ { "value": "This a test comment, please ignore" } ] }
curl -i -H "Content-Type: application/json" -b cookies.txt -X POST
mkdir ~/.drush
vim ~/.drush/aliases.drushrc.php
// local alias
$local_sites = '/users/paulbooker/Sites/';
$aliases[demo.local'] = array(
  'root' => $local_sites . 'demo',
  'path-aliases' => array(
    '%dump-dir' => $local_sites . 'drush.dbdumps',
    '%files' => $local_sites . 'demo/sites/default/files'
// remote alias
$remote_sites = '/var/www/sites/';
$aliases[''] = array(
  'remote-host' => '',
  'remote-user' => 'paulbooker',
  'root' => $remote_sites .',
  'path-aliases' => array(
    '%dump-dir' => '/home/paulbooker/drush.dbdumps',
    '%files' => $remote_sites .'
drush sql-sync @demo.local
$drush rsync @demo.local:%files
drush make patches.make
drush make --no-core --projects=rules patches.make
aptitude install php-pear
pear upgrade --force pear
pear install Console_GetoptPlus
pear install Console_Table
pear channel-discover
pear install drush/drush
sudo mkdir /home/backup
sudo chmod 700 /home/backup
#  ~/.drush/aliases.drushrc.php
$aliases['live'] = array(
  'uri'  => '',
  'root' => '/home/',

# Daily backup of the database, using Drush
# /usr/local/bin/

# Backup directory

log_msg() {
  # Log to syslog
  logger -t `basename $0` "$*"

  # Echo to stdout
  LOG_TS=`date +'%H:%M:%S'`
  echo "$LOG_TS - $*"

DAY_OF_WEEK=`date '+%a'`

log_msg "Backing up files and database to $BACKUP_FILE ..."

drush @live archive-dump \
  --destination=$BACKUP_FILE \
  --preserve-symlinks \


if [ "$RC" = 0 ]; then
  log_msg "Backup completed successfully ..."
  log_msg "Backup exited with return code: $RC"
chmod 755 /usr/local/bin/

.. add the script to cron..

30 2 * * * /usr/local/bin/
ls /home/backup/

scp or rsync backup files to another server

git clone --branch 7.x-1.x
git checkout -b 12345678-myproject-needs-fixing .
git format-patch 7.x-1.x --stdout > myproject-needs-fixing-12345678-1.patch .
paulbooker's picture

Drupal core security release window on Wednesday, August 6 (NOTE: Change from normal schedule)


2014-08-06 (All day) America/New_York


The monthly security release window for Drupal 6 and Drupal 7 core will take place on Wednesday, August 6.

Take note of the change in schedule! The security release window is normally the third Wednesday of the month, but we are moving it up for this month only to better coordinate various schedules. Apologies for any inconvenience this change might cause.

This does not mean that a Drupal core security release will necessarily take place on that date for either the Drupal 6 or Drupal 7 branches, only that you should prepare to look out for one (and be ready to update your Drupal sites in the event that the Drupal security team decides to make a release).

Due to the change in schedule and the fact that the Drupal 7.30 bug fix release was just a week ago, there will be no bug fix release in August; the next window for a Drupal core bug fix release is Wednesday, September 3.

For more information on Drupal core release windows, see the documentation on release timing and security releases, and the discussion that led to this policy being implemented.


Subscribe to Drupal Developer and Systems Administrator RSS