You are here

function clean_markup_blocks_preprocess_block in Clean Markup 7

Same name and namespace in other branches
  1. 7.3 modules/clean_markup_blocks/clean_markup_blocks.module \clean_markup_blocks_preprocess_block()
  2. 7.2 modules/clean_markup_blocks/clean_markup_blocks.module \clean_markup_blocks_preprocess_block()

Implements MODULE_preprocess_HOOK().

File

modules/clean_markup_blocks/clean_markup_blocks.module, line 166
Provides clean block markup.

Code

function clean_markup_blocks_preprocess_block(&$variables) {

  // Load defaults.
  $defaults = variable_get('clean_markup_blocks-defaults');

  // Get settings for this block.
  $variable_name = _clean_markup_blocks_generate_prefix($variables['block']->module, $variables['block']->delta);
  $current_block_settings = variable_get($variable_name, $defaults);

  // Copy simple settings into variables.
  $variables['block_wrapper'] = $current_block_settings['block_wrapper'];
  $variables['inner_div'] = $current_block_settings['enable_inner_div'];

  // Convert the additional block classes into an array, then merge into the
  // existing classes array. Note the use of check_plain to prevent XSS.
  $variables['classes_array'] = array_merge($variables['classes_array'], explode(' ', check_plain($current_block_settings['additional_block_classes'])));

  // Only output a title if one is set.
  if ($variables['block']->subject) {
    $variables['title'] = array(
      '#prefix' => render($variables['title_prefix']),
      '#suffix' => render($variables['title_suffix']),
      '#type' => 'html_tag',
      '#tag' => $current_block_settings['title_wrapper'],
      '#attributes' => isset($variables['title_attributes']) ? $variables['title_attributes'] : array(),
      '#value' => $variables['block']->subject,
    );
    $variables['title']['#attributes']['class'] = array(
      'title',
      'block-title',
    );
    if ($current_block_settings['title_hide']) {
      $variables['title']['#attributes']['class'][] = 'element-invisible';
    }
  }
  else {
    $variables['title'] = array();
  }

  // Only wrap the content if the user wants a wrapper.
  if ($current_block_settings['content_wrapper'] !== CLEAN_MARKUP_BLOCK_NO_ELEMENT) {
    $variables['content'] = array(
      '#type' => 'html_tag',
      '#tag' => $current_block_settings['content_wrapper'],
      '#attributes' => array(
        'class' => array(
          'content',
        ),
      ),
      '#value' => $variables['content'],
    );
    $variables['content']['#attributes'] += $variables['content_attributes_array'];
  }

  // Output the block HTML ID as a class if requested.
  if (array_key_exists('block_html_id_as_class', $current_block_settings) && $current_block_settings['block_html_id_as_class'] == TRUE) {
    $variables['classes_array'][] = $variables['block_html_id'];
  }
}