Weblinks API

Last modified: September 16, 2009 - 15:44

Hooks

With the introduction of a contributed modules architecture, there is a need for some communication between the "core" Web Links module and the add-ons. We have added some hooks where we felt they were needed to accomplish this. Additional hooks will be provided when the need arises.

Hook_weblinks_perm

This hook allows the contributed module to add its permissions into the "Weblinks" group on the permissions page so they are all together.

Parameters:

None

Return:

array of permissions
You can usually just change the name of your current hook_perms and it will work as desired.

Example:

/**
* Implementation of hook_weblinks_perm().
*/
function pralexa_weblinks_perm() {
  return array('Access Pagerank and Alexa');
}

Hook_weblinks_preprocess

This hook is called during "template_preprocess_weblinks_link" for building the variables that are available to the theme template.

Parameters:

$node
The complete node object for the current Web Links node.

Return:

array of variables
This will be in the same format as a standard "template_preproces_xxx". See Setting up variables for use in a template (preprocess functions).

Example:

/**
* Implementation of hook_weblinks_preprocess().
*/
function weblinks_checker_weblinks_preprocess($node) {
  if (variable_get('weblinks_checker_show_status', TRUE)) {
    return array('link_status' => theme('weblinks_status', $node));
  }
  else {
    return array();
  }
}

Hook_weblinks_extra_content

This hook is called when CCK queries about extra content fields. It allows the extra fields to be associated with the "weblinks" content type and made available to other modules.

Parameters:

none

Return:

array of fields
This will be in the same format as a standard "hook_content_extra_fields". See The Great Pretender: Making your data act like a field.

Example:

/**
* Implementation of hook_weblinks_extra_content().
* Tell CCK about our fields so the user can manage them.
*/
function pralexa_weblinks_extra_content() {
  $extras = array();

  $extras['rank_checked'] = array(
    'label' => t('Last rank checked date/time'),
    'description' => t('Date/time of the last ranking check.'),
    'weight' => 100,
    );
  $extras['pagerank'] = array(
    'label' => t('Google pagerank'),
    'description' => t('Google pagerank.'),
    'weight' => 100,
    );
  $extras['alexa'] = array(
    'label' => t('Alexa traffic rank'),
    'description' => t('Alexa traffic rank.'),
    'weight' => 100,
    );

  return $extras;
}

 
 

Drupal is a registered trademark of Dries Buytaert.