theme)) { $block->theme = $theme; } $attributes = block_class_attributes($block); $classes = array_key_exists('_', $attributes) ? $attributes['_'] : ''; if (array_key_exists($theme, $attributes)) { $classes .= ' ' . implode(' ', $attributes[$theme]); } return check_plain($classes); } /** * Extract the custom CSS class data for the given block. * * @param $block object Contains the keys 'module', 'delta', and 'theme'. * * @return array A map containing custom class information for the block. * The key '_' will map to any arbitrary class values that have * been entered for the block. Additionally, there will be a key * for each of the theme's block class group if a class from that * group has been specified. */ function block_class_attributes($block, $reset = FALSE) { static $blocks; // If we've not fetched the data, or we're being reset, fetch all the data: if (is_null($blocks) || $reset) { $result = db_query("SELECT module, delta, css_class FROM {block_class}"); while ($row = db_fetch_object($result)) { $blocks[$row->module][$row->delta] = unserialize($row->css_class); } } // Do we have info for this block: if (isset($blocks[$block->module][$block->delta])) { return $blocks[$block->module][$block->delta]; } else { return array('_' => ''); } } /** * Implementation of hook_form_FORM_ID_alter() for block_admin_configure. * Adds the block_class controls for block configurations. * * @param $form Nested array of form elements that comprise the form. * @param $form_state A keyed array containing the current state of the form. */ // TODO: This needs to be extended to work with the "block_add_block_form" form ID. // This may require reverting to the more general block_class_form_alter() implementation. function block_class_form_block_admin_configure_alter(&$form, &$form_state) { //-- Load any existing classes for this block. $block = new stdClass(); $block->module = $form['module']['#value']; $block->delta = $form['delta']['#value']; $block_info = module_invoke($block->module, 'block', 'list'); $attributes = block_class_attributes($block); $themes = list_themes(); $form['theme_block_classes'] = array( '#type' => 'fieldset', '#title' => t('Block classes'), '#collapsible' => TRUE, '#weight' => -1, '#description' => t('IMPORTANT: If your theme does not support Block Class out of the box, you must add <?php print $block_classes; ?> to its block.tpl.php file so that the classes will be added. See the module\'s README.txt for more details.'), ); //-- Loop through the themes, and for active themes with block-class //-- entries in their .info files, display options for those. foreach($themes as $theme) { if ($theme->status > 0) { $info = $theme->info; $block_classes = $info['block-class']; if (count($block_classes) > 0) { $form['theme_block_classes']['themes'][$theme->name] = array( '#type' => 'fieldset', '#title' => t('@theme Block Classes', array('@theme' => $info['name'])), '#collapsed' => TRUE, '#collapsible' => TRUE, '#description' => t('The selected classes will be applied to this block when it is displayed using the @theme theme.', array('@theme' => $info['name'])), ); $options = drupal_map_assoc($block_classes); $form['theme_block_classes']['themes'][$theme->name][$theme->name . '-classes'] = array( '#type' => 'checkboxes', '#title' => t('Classes'), '#options' => $options, '#default_value' => empty($attributes[$theme->name]) ? array() : $attributes[$theme->name], '#element_validate' => array(''), ); } } } //-- The arbitrary class text field. $form['theme_block_classes']['css_class'] = array( '#type' => 'textfield', '#title' => t("Global CSS for '#block' block", array('#block' => $block_info[$block->delta]['info'])), '#default_value' => empty($attributes['_']) ? '' : $attributes['_'], '#description' => t('Enter CSS classes not defined in the theme here. These will be applied to the block in every Block Class enabled theme. Separate classes with a space.'), ); $form['#submit'][] = 'block_class_form_submit'; } /** * Handle submission of the Block Class data. * * @param $form The array of form elements. * @param &$form_state The form field data. * * @TODO (low priority) validate the text in the arbitrary text field to verify */ function block_class_form_submit($form, &$form_state) { $themes = list_themes(); foreach($themes as $theme) { if ($theme->status > 0) { drupal_set_message(print_r($form_state['values'][$theme->name . '-classes'], TRUE)); } } drupal_set_message(print_r($form_state['values']['css_class'], TRUE)); }