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)));
    }
  }
}

Drupal – Skipping require fields errors

function hook_form_validate($form, &$form_state) {
  $errors = form_get_errors();

  if ($errors) {
    // Clear errors.
    form_clear_error();
    // Clear error messages.
    $error_messages = drupal_get_messages('error');
    // Initialize an array where removed error messages are stored.
    $removed_messages = array();

    // Remove all errors originated by the 'foo][bar' element.
    foreach ($errors as $name => $error_message) {
      if ($name == 'body][und][0][value') {
        $removed_messages[] = $error_message;
        unset($errors[$name]);
      }
    }

    // Reinstate remaining errors.
    foreach ($errors as $name => $error) {
      form_set_error($name, $error);
      // form_set_error() calls drupal_set_message(), so we have to filter out
      // these from the error messages as well.
      $removed_messages[] = $error;
    }

    // Reinstate remaining error messages (which, at this point, are messages that
    // were originated outside of the validation process).
    foreach (array_diff($error_messages['error'], $removed_messages) as $message) {
      drupal_set_message($message, 'error');
    }
  }
}

Source: http://goo.gl/nI55mb