View source
<?php
function block_class_menu($may_cache) {
if (!$may_cache && strpos($_GET['q'], 'admin/build/block/configure/') === 0 && isset($_POST['css_class']) && user_access('administer blocks')) {
$module = arg(4);
$delta = arg(5);
$class = $_POST['css_class'];
db_query('DELETE FROM {block_class} WHERE module = "%s" AND delta = "%s"', $module, $delta);
if (!empty($class)) {
db_query('INSERT INTO {block_class} (module, delta, css_class) VALUES ("%s", "%s", "%s")', $module, $delta, $class);
}
}
}
function block_class($block) {
$attributes = block_class_attributes($block);
return check_plain($attributes->css_class);
}
function block_class_attributes($block) {
$ret = db_fetch_object(db_query('SELECT css_class FROM {block_class} WHERE module = "%s" AND delta = "%s"', $block->module, $block->delta));
if ($ret !== FALSE) {
return $ret;
}
$undef = (object) NULL;
$undef->css_class = '';
return $undef;
}
function block_class_form_alter($form_id, &$form) {
if ($form_id == 'block_admin_configure') {
$block->module = $form['module']['#value'];
$block->delta = $form['delta']['#value'];
$attributes = block_class_attributes($block);
$form['block_class'] = array(
'#type' => 'fieldset',
'#title' => t('Block Class settings'),
'#collapsible' => TRUE,
'#weight' => -1,
);
$form['block_class']['css_class'] = array(
'#type' => 'textfield',
'#title' => t('CSS class(es)'),
'#default_value' => $attributes->css_class,
'#description' => t('Separate classes with a space. IMPORTANT: You must add <?php print block_class($block); ?> to your theme\'s block.tpl.php file to make the classes appear.'),
);
}
}