Certain things compel people

“Still,” he says, “certain things compel people. Pearls, for example, and sinistral shells, shells with a left-handed opening. Even the best scientists feel the urge now and then to put something in a pocket. That something so small could be so beautiful. Worth so much. Only the strongest people can turn away from feelings like that.”

– Dr. Geffard, All the Light We Cannot See, page 52

Drupal Workbench: Assigning revision owner when moderating backwards with Workbench

<?php

/**
 * Implements hook_node_update().
 */    
function mymodule_node_update($node) {
  db_update('node_revision')
    ->fields(array('uid' => $node->uid))
    ->condition('nid', $node->nid)
    ->condition('vid', $node->vid)
    ->execute();
}

/**
 * Implements hook_workbench_moderation_transition().
 */
function mymodule_workbench_moderation_transition($node, $previous_state, $new_state) {
  if (isset($node->nid) && isset($node->vid) && isset($node->uid)) {
    mymodule_node_update($node);
  }
}

Source: http://goo.gl/VT0qS9

Drupal: Allow HTML in node title

<?php
 
/* 
 * This function generates the variables that are available in your node.tpl,
 * you should already have this in your template.php, but if not, create it.
 */
function mytheme_preprocess_node(&$vars) {
    // It's important to run some kind of filter on the title so users can't
    // use fx script tags to inject js or do nasty things.
    $vars['title'] = filter_xss($vars['node']->title);
}

Source: http://goo.gl/mUBcPj

Drupal: Make regions available from node.tpl.php

<?php
/**
 * Then render any region like
 * <?php print render($region['sidebar_first']); ?>
 */

function mytheme_preprocess_node(&$variables) {

  // Get a list of all the regions for this theme
  foreach (system_region_list($GLOBALS['theme']) as $region_key => $region_name) {

    // Get the content for each region and add it to the $region variable
    if ($blocks = block_get_blocks_by_region($region_key)) {
      $variables['region'][$region_key] = $blocks;
    }
    else {
      $variables['region'][$region_key] = array();
    }
  }
}

Source: http://goo.gl/ZCdXwK

Drupal – Reverting Feature modules

<?php

/**
 * Revert specified features.
 *
 * @TODO Check that it really is Forced features revert.  Currently an exact
 * copy of the function initially placed in feature_projects.install.
 *
 * Code mostly taken from drush.
 *
 * Source: Reverting features in update hooks requires a helper function
 * (http://goo.gl/MKSd11)
 */
function _features_revert($modules) {
  module_load_include('inc', 'features', 'features.export');
  features_include();

  foreach ($modules as $module) {
    $components = array();
    
    if (($feature = feature_load($module, TRUE)) && module_exists($module)) {

      // Forcefully revert all components of a feature.
      foreach (array_keys($feature->info['features']) as $component) {
        if (features_hook($component, 'features_revert')) {
          $components[] = $component;
        }
      }
    }

    foreach ($components as $component) {
      features_revert(array($module => array($component)));
    }
  }
}