mysite_block_handler

Definition

mysite_block_handler($data)
mysite.module, line 2937

Description

Data handling for block placement. This function is part of the API.

Returns links to MySite actions to the mysite_block() based on the current path.

Called by the mysite_type_hook_block() functions, this allows all block links to be formatted by a single function.

Parameters

$data The $data array prepared by mysite_type_hook_block(). The $data array takes the format:

  • 'uid': The user id of the person viewing the page.
  • 'type': The content type defined by this include.
  • 'type_id': The id key for this particular page. That is, if viewing 'taxonomy/term/2', this value is '2'.

Return value

The content to be displayed by mysite_block().

Code

function mysite_block_handler($data) {
  if (isset($data['type_id'])) {
    // has the user already saved this?
    $mid = mysite_check($data['uid'], $data['type'], $data['type_id']);
    // Get the title of this content.
    $func = "mysite_type_". $data['type'] ."_title";
    $title = $func($data['type_id']);
    if ($mid <= 0) {
      $link = mysite_add_link($data['uid'], $data['type'], $data['type_id']);
      $content = '<ul><li>'. l(t("Add !name to your personal page", array('!name' => $title)), $link) .'</li></ul>';
    }
    else {
      $link = mysite_remove_link($data['uid'], $mid);
      $content = '<ul><li>'. l(t("Remove !name from your personal page", array('!name' => $title)), $link) .'</li></ul>';
    }
    return $content;
  }
}