The $variables['content'] variable contains the content of the block to be displayed. The individual elements come from $variables['elements']. If you add:
debug(array_keys($variables['elements']));
to the script, you get the following output:
array (
0 => 'whois_form',
1 => 'whois_lookup_data',
2 => '#block',
3 => '#weight',
4 => '#theme_wrappers',
5 => '#children',
)
When looking at these in detail, you see that $variables['elements']['#children'] is comprised of $variables['elements']['whois_form']['#children'] and $variables['elements']['whois_lookup_data']['#children'].
Ultimately, $variable['content'] is comprised of $variable['elements']['#children'] (see also https://api.drupal.org/api/drupal/modules!block!block.module/function/template_preprocess_block/7)
So, there are two options:
- Alter $variables['elements']['whois_lookup_data']['#children'], and recreate $variable['elements']['#children']
- Alter $variable['elements']['#children'] directly.
I chose the second option below.
To use the hook_preprocess_block hook, as shown below, the core module "Block" needs to be enabled.
name = Whois Alter Module
description = A module to change the output of whois.
core = 7.x
package = Drupal 7 Misc
files[] = whois_alter.module
dependencies[] = block
dependencies[] = whois
<?php
// $Id$
/**
* @file
* A module to demonstrate hook_preprocess_block to alter the output of another module
*
* This module alters the output of the whois module
*/
/**
* Implements hook_help().
*/
function whois_alter_help($path, $arg) {
if ($path == 'admin/help#whois_alter') {
return t('A module to alter whois output.');
}
}
/**
* Implements hook_block_info().
*/
function whois_alter_block_info() {
$blocks = array();
$blocks['list_modules'] = array(
'info' => t(' Alters the output of the whois module'),
'cache' => DRUPAL_NO_CACHE,
);
return $blocks;
}
/**
* Implements hook_preprocess_block().
*/
function whois_alter_preprocess_block(&$variables, $hook){
if (isset($variables['elements']['whois_lookup_data'])) {
$whois_modified = whois_alter_modify_whois($variables['elements']['whois_lookup_data']['#children']$variables['elements']['#children']);
$variables['elements']['whois_lookup_data']['#children']$variables['elements']['#children'] = $whois_modified;
$variables['content'] = $variables['elements']['whois_lookup_data']['#children'];$variables['elements']['#children'];
}
}
function whois_alter_modify_whois($content) {
// do what you want to do to modify the output
return $altered_content;
}
function yourtheme_preprocess_block(&$variables, $hook){
if (isset($variables['elements']['whois_lookup_data'])) {
$whois_modified = yourtheme_modify_whois($variables['elements']['whois_lookup_data']['#children']$variables['elements']['#children']);
$variables['elements']['whois_lookup_data']['#children']$variables['elements']['#children'] = $whois_modified;
$variables['content'] = $variables['elements']['whois_lookup_data']['#children'];$variables['elements']['#children'];
}
}
function yourtheme_modify_whois($content) {
// do what you want to do to modify the output
return $altered_content;
}