Blog

Drupal DBinfo Module Maintainer!

The ESCI project is currently within a Live window again. Prior to release on Monday, March 7, 2013 at midnight I was reviewing last minute issues I felt I could remedy. The Friday leading to the weekend I got the idea it would be nice if I could see the status of the databases ESCI can connect to. This led me to hack out the DBinfo module overnight.

The project has completed the vetting process and will shortly be released as a Full Project shortly.

ESCI Beta Preview

Long time since a last post. I have been working non-stop for about 1 month and a bit on the UCSB ESCI Website. ESCI is UCSB's campus-wide course survey and evaluation tool which has been in production for the last 30 years here at UCSB. My parent department runs the ESCI Survey System which has historically been scantron based and processed, tabulated once at the end of every quarter. To be more Green, sustainable and adaptive in the future we are moving this service to a web based service for students and faculty alike here at UCSB. I have been working on a Drupal based replacement for the scantrons students previously were submitting. This service is now in a Beta test with approximately 500 students. The next big rollout approaching campus wide usage is planned for March.

Given some free time in the near future I will try to discuss some of its current underlying implementation involving Drupal and a brief look at its integration and consumption of campus and departmental data and webservices it currently uses.

Creating D7 OG groups programmatically

This is a crosspost to a D.o issue I replied to since I recently had to create groups programmatically in Drupal 7.

Drupal 6/7 have drupal_execute() for D6 and drupal_form_submit() for D7 to programmatically submit forms. If you install OG and create a content type for your groups -- you can then programmatically submit the form via a Drush script or a module update using core drupal functions.

An example of inspecting, and how to understand a POST of node creation form and also using drupal_form_submit() can be found here, and some nifty Firebug usage: Programmatically create nodes tutorial

As an example the php script I created and then ran via "drush php-script" was as follows to create about a dozen groups on-the-fly in D7:

/*
 * Eg filename "make-groups.php"
 * run via "drush -l {SITENAME_URI} php-script make-groups.php
 */

/* include this if you run this within a module to assure * the node_form() functions have been included for the code * you're about to run ... */ module_load_include('inc', 'node', 'node.pages');

/* groups to create. */ $areas = array( 'group1', 'group2', 'group3', );

foreach ($areas as $area) { $form_state = array(); /* these are essentially cookie-cutter fields shared by most * any node type. */ $form_state['values']['body']['und'][0]['format'] = 2; $form_state['values']['body']['und'][0]['summary'] = ''; $form_state['values']['body']['und'][0]['value'] = ''; $form_state['values']['book']['bid'] = 0; $form_state['values']['book']['plid'] = -1; $form_state['values']['book']['weight'] = 0; $form_state['values']['changed'] = ''; $form_state['values']['date'] = ''; $form_state['values']['log'] = ''; $form_state['values']['op'] = t('Save'); $form_state['values']['path']['alias'] = ''; $form_state['values']['revision'] = 1; $form_state['values']['status'] = 1; $form_state['values']['language'] = LANGUAGE_NONE;

/* these are the 2 fields that we actually care about for groups. */
$form_state['values']['title'] = $area;
$form_state['values']['group_group']['und'] = 1;

$newNode = new stdClass();
/* the machine name of the OG group you created. */
$newNode->type = "idgroup";
$newNode->language= LANGUAGE_NONE;
$newNode->options = array();
$newNode->uid = 1;
$newNode->promote = 0;
$newNode->module = 'node';
node_object_prepare($newNode);

/* Call your content type's node create form passing a
 * canned $form_state and a bare-bones node object.
 */
drupal_form_submit('idgroup_node_form', $form_state, $newNode);

}

Adding SunlightJS Syntax Highlighter to Drupal 7

Curiously looking for a decent, extensible syntax highlighting package to add to this blog I stumbled across sunlightjs which supports colorschemes, language definitions and gracefully degrades.

Simply extracting the sunlightjs sourcecode archive to your Drupal /themes folder and applying the following additions to your theme.info file will essentially make this package work on your drupal site.

stylesheets[all][] = sunlight-1.8.341/themes/sunlight.dark.css
scripts[] = sunlight-1.8.341/sunlight-min.js
scripts[] = sunlight-1.8.341/lang/sunlight.bash-min.js
scripts[] = sunlight-1.8.341/lang/sunlight.javascript-min.js
scripts[] = sunlight-1.8.341/lang/sunlight.mysql-min.js
scripts[] = sunlight-1.8.341/lang/sunlight.nginx-min.js
scripts[] = sunlight-1.8.341/lang/sunlight.php-min.js
scripts[] = sunlight-1.8.341/lang/sunlight.ruby-min.js

Lastly, you must activate sunlightjs for the content in question. For this site I essentially want syntax highlighting within the blog section of the site. So we'll write a simple module function for davidgurba.com that inserts the activation javascript from the sunlightjs documentation page for all blog pages.

/** implementation of hook_node_view() */
function dgcom_node_view($node, $view_mode, $langcode) {
  if ($node->type === 'blog_entry') {
    drupal_add_js('Sunlight.highlightAll();',
        array('type' => 'inline', 'scope' => 'footer', 'weight' => 5)
    );
  }
}

This blog post is an example of "eating your own dog food", eg this post utilizes all the code discussed herein.

More to Come ...

I will try to post interesting coding tidbits I produce or come across here. Mainly at work I have been developing software solutions using the Drupal CMS. Hopefully I will be able to post various coding techniques or innovations I author on behalf of my work.

I also want to show other interests I have in this spot such as reading and martial arts. Have a great day!

Subscribe to David Gurba Blog