Adding a Machine Name CSS Class to Drupal Blocks When Using Features Extra

If you're capturing custom blocks in Drupal with Features and Features Extra, you may want to add custom CSS styling to those blocks. Unfortunately, by default there are no CSS classes on the blocks that will stay consistent from development to production. (because the block IDs may change) The following preprocess function added to your theme will add a class based on the machine name of the block:

<?php
/**
  * Implements hook_preprocess_block()
  */
function yourtheme_preprocess_block(&$variables){ 
 
// Add class for feature machine name 
 
if (module_exists('fe_block') && $variables['elements']['#block']->module == 'block') {   
   
$machine_name = db_query("SELECT machine_name FROM {fe_block_boxes} WHERE bid = :bid", array('bid' => $variables['elements']['#block']->delta))->fetchField();
    if (!empty(
$machine_name)) {
     
$variables['classes_array'][] = 'block--' . str_replace('_', '-', $machine_name);   
    } 
  }
}
?>