Coming from using boxes I am used to a way to add classes to boxes blocks. What is the best way to add classes to bean?

Should we use www.dgo.to/block_class?

Comments

Do you want to add classes to the bean (in the block content) or the parent block itself?

If the former, you can use template_preprocess_bean(&$variables) and if the latter you can use template_preprocess_block(&$variables) and add classes to the $variables['classes_array'].

See this page for info about preprocess functions: http://drupal.org/node/223430

For example (in your theme's template.php file):

This example adds a custom class to the bean:

<?php
/**
* Override or insert variables into the bean templates.
*/
function YOURTHEME_preprocess_bean(&$variables) {
 
// Add a custom class to the bean entity.
 
$variables['classes_array'][] = 'my-custom-class';
}
?>

This example adds a class to the parent block that contains the bean type and also adds a template suggestion based on the bean type:

<?php
/**
* Override or insert variables into the block templates.
*/
function YOURTHEME_preprocess_block(&$variables) {
 
// For bean blocks.
 
if ($variables['block']->module == 'bean') {
   
// Get the bean elements.
   
$beans = $variables['elements']['bean'];
   
// There is only 1 bean per block.
   
$bean = $beans[reset(element_children($beans))];
   
// Add bean type classes to the parent block.
   
$variables['classes_array'][] = drupal_html_class('block-bean-' . $bean['#bundle']);
   
// Add template suggestions for bean types.
   
$variables['theme_hook_suggestions'][] = 'block__bean__' . $bean['#bundle'];
  }
}
?>

Actually it seems that for some reason template_preprocess_bean() does not work.

Status:Active» Fixed

Instead of template_preprocess_bean() you could do this:

<?php
function YOURTHEME_process_entity(&$variables) {
  if (
$variables['entity_type'] == 'bean') {
    if (
$variables['bean']->type == 'YOUR_BEAN_TYPE') {
     
$variables['classes_array'][] = 'your-custom-class';
    }
  }
}
?>

Also, for more themeing chat see #1361756: More theme candidates.

Marking fixed, if you still require more help feel free to reopen.

Status:Fixed» Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

rooby's suggestion above got me on the right track. However, I couldn't get my modified classes_array to output to the page with hook_process_entity. I had to use the following, which came from the suggestion #1361756: More theme candidates:

<?php
function YOURTHEME_preprocess_block(&$variables) {
  if (
$variables['block']->module == 'bean') {
     
$variables['classes_array'][] = 'your-custom-class';
  }
}
?>