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

Drupal: Basic Workbench configuration

Install and enable the following modules and their respective dependencies (Views and Chaos tools):
– Workbench
– Workbench Access
– Workbench Moderation

Edit all content types that will go through the workflow
– Under Publishing options, uncheck the following options:
– Published
– Under Publishing options, check the following options:
– Create new revision
– Enable moderation of revisions
– Enforce Workbench Access control
– Under Publishing options, make sure the Default moderation state is set to Draft

Go to permissions and check the following permissions for the Author
– View published content
– View own unpublished content
– View content revisions
– “Create new content” and “Edit own content” for all the appropriate content types
– View the administration theme
– Use the administration toolbar
– Access My Workbench
– Allow all members of this role to be assigned to Workbench Access sections
– View moderation history
– View the moderation messages on a node
– Use “My Drafts” workbench tab
– Moderate all content from Draft to Needs Review

Go to permissions and check the following permissions for Publishers
– Administer menus and menu items
– View published content
– View own unpublished content
– View content revisions
– Revert content revisions
– Delete content revisions
– “Create new content”, “Edit any content”, and “Delete any content” for all the appropriate content types
– View the administration theme
– Use the administration toolbar
– Access My Workbench
– Allow all members of this role to be assigned to Workbench Access sections
– View all unpublished content
– View moderation history
– View the moderation messages on a node
– Use “My Drafts” workbench tab
– Use “Needs Review” workbench tab
– Moderate all content from Draft to Needs Review
– Moderate all content from Needs Review to Draft
– Moderate all content from Needs Review to Published

Go to Taxonomy and add a new vocabulary. Name it “Content Workflow”
Add the following terms:
– Content Publishers
– Content Authors
– Under Relations fieldset, select Content Publishers as the parent term

Go to the Workbench Access from the admin configuration page.
Go to the Settings tab
Check the Content Workflow under the Taxonomy Scheme Settings fieldset
Under the Content Types enabled, make sure all the appropriate content types are checked

Go to Roles tab
Click the 0 roles link of Content Publishers
Check the publisher role
Click the 0 roles link of the Content Authors
Check the author tab

Go to the Workbench Moderation from the admin configuration page.
Go to Transitions tab