Web design, programming, graphics, and pretty much anything else I care about.

drupal

Drupal Camp NJ 2013

DrupalCampNJ 2013 (http://www.drupalcampnj.org/) is February 2nd. I will be presenting a session on System Tips and Tricks (http://www.drupalcampnj.org/content/system-tips-and-tricks).

Joins can't be chained using Drupal 7 dynamic queries

I had a problem with a query I was building for a site migration from Drupal 6 to 7. I'm building the query dynamically as an object in Drupal 7. (The details aren't important.)

<?php
$query
= db_select('users_roles', 'r')
             ->
fields('r', array('uid', 'rid'))
             ->
condition('r.uid', $source_id, '=');
$results = $query->execute();
?>

Bootstrapping Drupal from an external sript

There are occasions where connecting to Drupal from an external script comes in handy. Connecting from a non-Drupal system, performing simple maintenance tasks, or just quick and dirty one time operations where you don't feel like making a module. I do this often when creating import scripts to bring data into a new site.

DrupalCamp NJ 2012 and sprint

DrupalCampNJ 2012 is this weekend. http://www.drupalcampnj.org/ . I'm helping organize and sponsor the event. The Sunday after (I know, Super Bowl Sunday :-() we are having a code sprint, and I'm helping organize a "How to Contribute" sprint to show new people how to contribute back to Drupal. I'll be going over documentation, patching, testing, providing support, etc. If you are interested, let me know. The sprint will go from ~10am - 5pm, and you can come and go as you please, so there is plenty of time to get home for the Super Bowl.

Discover CCK field table and column information

When retrieving information from the database for CCK fields, you can't assume the schema. Fields may be added to the content table, but if they are included on more than one content type, they get moved to their own table. Because things might move around, you can't make assumptions about where they will be. CCK api has functions you can use to determine where things are located.

Creating date repeat rules

Because Date doesn't play well with drupal_execute(), you have to use node_save() to insert/update nodes. If those nodes have a date field that uses repeats, you have to manually create the date array and repeat rule. ugh!

Programmatically inserting nodes

Inserting nodes, programmatically, is not always the easiest thing. The "drupally" way of doing it is to build the node form array and then submit it to drupal_execute(). (http://api.drupal.org/api/drupal/includes--form.inc/function/drupal_exec...) This follows the same procedure that the node/add form follows. This method will make sure that all the same validations occur, permission checks, etc. The problem is this is a slow process, and some modules don't work well with drupal_execute; namely, Date. To insert modules that have date fields, use node_save().

Install taxonomy, with terms and hierarchy, on module installation

Getting a module to install a vocabulary, and even import terms, is not terribly difficult; however, getting it to accept an existing hierarchy can be tricky.

(I was working with a taxonomy for academic departments and schools.)

Create an include file. I name them module name.taxonomy.def.inc. In the file create an array that will define the vocabulary, and one that will include the terms.

Configure CCK fields on module installation

You can have a module installation automatically add and configure CCK field. First, setup the CCK fields on a development site exactly as you want them. Then, export the fields from /admin/content/types/export.

You will end up with the code for a php array that looks something like ...

Update email send time always incremented by one cron run

I enabled the update feature that emails me whenever the site has an update available. I noticed that the time the email gets sent is always incremented by one cron run. For example, I have cron running hourly, so if there are updates needed it will email me at 8am, the next day at 9am, the next day at 10am, etc. But, based on the math, whatever interval cron runs at the email will likely always be one run later.

In hook_cron, the if statement requires the current time to be greater than interval (in my case, 24hrs). If it is exactly 24hrs, it will not pass.