Skip to main content
added clarification, fixed bug and removed unnecessary code
Source Link
Ursula
  • 654
  • 4
  • 12

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:

  1. Alter $variables['elements']['whois_lookup_data']['#children'], and recreate $variable['elements']['#children']
  2. 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;
}

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
<?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']['whois_lookup_data']['#children'] = $whois_modified;
     $variables['content'] = $variables['elements']['whois_lookup_data']['#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']['whois_lookup_data']['#children'] = $whois_modified;
     $variables['content'] = $variables['elements']['whois_lookup_data']['#children'];
  }
}


function yourtheme_modify_whois($content) {
   // do what you want to do to modify the output
   return $altered_content;
}

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:

  1. Alter $variables['elements']['whois_lookup_data']['#children'], and recreate $variable['elements']['#children']
  2. 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_preprocess_block().
*/

function whois_alter_preprocess_block(&$variables, $hook){
  
  if (isset($variables['elements']['whois_lookup_data'])) {
     $whois_modified = whois_alter_modify_whois($variables['elements']['#children']);
     $variables['elements']['#children'] = $whois_modified;
     $variables['content'] = $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']['#children']);
     $variables['elements']['#children'] = $whois_modified;
     $variables['content'] = $variables['elements']['#children'];
  }
}


function yourtheme_modify_whois($content) {
   // do what you want to do to modify the output
   return $altered_content;
}
added block module requirement and more details
Source Link
Ursula
  • 654
  • 4
  • 12

If I understand your question correctly, you want to write a module that hooks into the whois module to alter the returned content.

The general method has been described here: Hooking into a contrib module

The whois module doesn't provide a hook.

However, youYou can change the output through preprocessing, for example in your theme's template.php file, or in your custom module (see also: https://api.drupal.org/api/drupal/modules!system!theme.api.php/function/hook_preprocess_HOOK/7). 

To use the hook_preprocess_block hook, as shown below, the core module "Block" needs to be enabled.

If used in a module, in yourmodule.info:

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

In yourmodulewhois_alter.module or your theme's:

<?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']['whois_lookup_data']['#children'] = $whois_modified;
     $variables['content'] = $variables['elements']['whois_lookup_data']['#children'];
  }
}


function whois_alter_modify_whois($content) {
   // do what you want to do to modify the output
   return $altered_content;
}

For Theme preprocessing, just use the functional part of the module in template.php:

function yourthemeormodule_preprocess_blockyourtheme_preprocess_block(&$variables, $hook) {
  
  if (isset($variables['elements']['whois_lookup_data'])) {
 
     $whois_modified = yourthemeormodule_modify_whoisyourtheme_modify_whois($variables['elements']['whois_lookup_data']['#children']);
     $variables['elements']['whois_lookup_data']['#children'] = $whois_modified;
     $variables['content'] = $variables['elements']['whois_lookup_data']['#children'];
 
  }
 
}  


function yourthemeormodule_modify_whoisyourtheme_modify_whois($content) {
   // do what you want to do to modify the output
   return $altered_content;
}

If I understand your question correctly, you want to write a module that hooks into the whois module to alter the returned content.

The general method has been described here: Hooking into a contrib module

The whois module doesn't provide a hook.

However, you can change the output through preprocessing, for example in your theme's template.php file, or in your custom module (see also: https://api.drupal.org/api/drupal/modules!system!theme.api.php/function/hook_preprocess_HOOK/7). To use the hook_preprocess_block hook, the core module "Block" needs to be enabled.

If used in a module, in yourmodule.info:

dependencies[] = block

In yourmodule.module or your theme's template.php:

function yourthemeormodule_preprocess_block(&$variables, $hook) {

  if (isset($variables['elements']['whois_lookup_data'])) {
 
     $whois_modified = yourthemeormodule_modify_whois($variables['elements']['whois_lookup_data']['#children']);
     $variables['elements']['whois_lookup_data']['#children'] = $whois_modified;
     $variables['content'] = $variables['elements']['whois_lookup_data']['#children'];
 
  }
 
} 

function yourthemeormodule_modify_whois($content) {
   // do what you want to do to modify the output
   return $altered_content;
}

You can change the output through preprocessing, for example in your theme's template.php file, or in your custom module (see also: https://api.drupal.org/api/drupal/modules!system!theme.api.php/function/hook_preprocess_HOOK/7). 

To use the hook_preprocess_block hook, as shown below, the core module "Block" needs to be enabled.

If used in a module, in yourmodule.info:

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

In whois_alter.module:

<?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']['whois_lookup_data']['#children'] = $whois_modified;
     $variables['content'] = $variables['elements']['whois_lookup_data']['#children'];
  }
}


function whois_alter_modify_whois($content) {
   // do what you want to do to modify the output
   return $altered_content;
}

For Theme preprocessing, just use the functional part of the module in template.php:

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']['whois_lookup_data']['#children'] = $whois_modified;
     $variables['content'] = $variables['elements']['whois_lookup_data']['#children'];
  }
} 


function yourtheme_modify_whois($content) {
   // do what you want to do to modify the output
   return $altered_content;
}
added block module requirement
Source Link
Ursula
  • 654
  • 4
  • 12

If I understand your question correctly, you want to write a module that hooks into the whois module to alter the returned content.

The general method has been described here: Hooking into a contrib module

Unfortunately, theThe whois module doesn't provide a hook.

However, you can change the output through preprocessing, for example in your theme's template.php file, or in your custom module (see also: https://api.drupal.org/api/drupal/modules!system!theme.api.php/function/hook_preprocess_HOOK/7). To use the hook_preprocess_block hook, the core module "Block" needs to be enabled.

If used in a module, in yourmodule.info:

dependencies[] = block

In yourmodule.module or your theme's template.php:

function yourthemeormodule_preprocess_block(&$variables, $hook) {

  if (isset($variables['elements']['whois_lookup_data'])) {

     $whois_modified = yourtheme_modify_whoisyourthemeormodule_modify_whois($variables['elements']['whois_lookup_data']['#children']);
     $variables['elements']['whois_lookup_data']['#children'] = $whois_modified;
     $variables['content'] = $variables['elements']['whois_lookup_data']['#children'];

  }

} 

function yourthemeormodule_modify_whois($content) {
   // do what you want to do to modify the output
   return $altered_content;
}

If I understand your question correctly, you want to write a module that hooks into the whois module to alter the returned content.

The general method has been described here: Hooking into a contrib module

Unfortunately, the whois module doesn't provide a hook.

However, you can change the output through preprocessing, for example in your theme's template.php file, or in your custom module (see also: https://api.drupal.org/api/drupal/modules!system!theme.api.php/function/hook_preprocess_HOOK/7):

function yourthemeormodule_preprocess_block(&$variables, $hook) {

  if (isset($variables['elements']['whois_lookup_data'])) {

     $whois_modified = yourtheme_modify_whois($variables['elements']['whois_lookup_data']['#children']);
     $variables['elements']['whois_lookup_data']['#children'] = $whois_modified;
     $variables['content'] = $variables['elements']['whois_lookup_data']['#children'];

  }

} 

function yourthemeormodule_modify_whois($content) {
   // do what you want to do to modify the output
   return $altered_content;
}

If I understand your question correctly, you want to write a module that hooks into the whois module to alter the returned content.

The general method has been described here: Hooking into a contrib module

The whois module doesn't provide a hook.

However, you can change the output through preprocessing, for example in your theme's template.php file, or in your custom module (see also: https://api.drupal.org/api/drupal/modules!system!theme.api.php/function/hook_preprocess_HOOK/7). To use the hook_preprocess_block hook, the core module "Block" needs to be enabled.

If used in a module, in yourmodule.info:

dependencies[] = block

In yourmodule.module or your theme's template.php:

function yourthemeormodule_preprocess_block(&$variables, $hook) {

  if (isset($variables['elements']['whois_lookup_data'])) {

     $whois_modified = yourthemeormodule_modify_whois($variables['elements']['whois_lookup_data']['#children']);
     $variables['elements']['whois_lookup_data']['#children'] = $whois_modified;
     $variables['content'] = $variables['elements']['whois_lookup_data']['#children'];

  }

} 

function yourthemeormodule_modify_whois($content) {
   // do what you want to do to modify the output
   return $altered_content;
}
wrong variable name
Source Link
Ursula
  • 654
  • 4
  • 12
Loading
clarified theme or module possibility
Source Link
Ursula
  • 654
  • 4
  • 12
Loading
Source Link
Ursula
  • 654
  • 4
  • 12
Loading