Hi Nick,

thx for this simple but very usefull module.

For your information, see the code below to see how I adjust the preprocess_block to support the l() fonction of drupal (who take care of the eventual subdirectory where drupal is installed, etc ...).
I added a class to the a href to be able to style this link in my theme style.css file.
By using $vars['block']->subject, I do not need to adjust the block.php

Regards,

/**
 * Implementation of hook_preprocess_block
**/

function block_titlelink_preprocess_block(&$vars, $hook) {  
  if ($hook == 'block') {
    $var_name = $vars['block']->module .'_'. $vars['block']->delta;
    //$vars['block']->title_link = _block_titlelink_get_link($vars['block']);
    $tmp=_block_titlelink_get_link($vars['block']);
    if (trim($tmp)!='') {
      $vars['block']->subject = l($vars['block']->subject,$tmp, array('attributes' => array('class' => 'block-title-link')) );
    }
  }
}

Comments

AlexanderPop’s picture

Thank you. It solved my problem http://drupal.org/node/662314. Now it works.

ngmaloney’s picture

@nico059 Thanks for the code snippet. Would it make sense to integrate your preprocess hook into the module?

danny englander’s picture

Thank you, this fixed my issue as well. In my case I had a block created from a view. Once I added the code above, all was well!

nevets’s picture

Minor point but the code can be simplified to

<?php
/**
* Implementation of hook_preprocess_block
**/

function block_titlelink_preprocess_block(&$vars) { 

  $tmp=_block_titlelink_get_link($vars['block']);
  if (trim($tmp)!='') {
    $vars['block']->subject = l($vars['block']->subject,$tmp, array('attributes' => array('class' => 'block-title-link')) );
  }
}
?>

(since its an instance of hook_preprocess_block it already knows its a block)

Ela’s picture

To which file do I add this code? :)

nevets’s picture

The code would go in your themes template.php file

Ela’s picture

Thank you :)

jmcintyre’s picture

The approaches recommended above worked for me, but they broke my site when I disabled the Block Title Link module... why not add this capability into the module itself, rather than relying using a theme hook? Sorry that I don't have CVS access set up yet and can't offer this as a patch. It's an easy fix, though, to the function beginning on line 65 of block_titlelink.module:


/**
 * Implementation of hook_preprocess_block
**/
function block_titlelink_preprocess_block(&$vars, $hook) {  
  if ($hook == 'block') {
    $var_name = $vars['block']->module .'_'. $vars['block']->delta;
    $vars['block']->title_link = _block_titlelink_get_link($vars['block']);
// ***THE FIX*** Add the link HTML to the block's title
    $tmp = $vars['block']->title_link;
    if ($tmp != '') {
        $vars['block']->subject = l($vars['block']->subject,$tmp, array('attributes' => array('class' => 'block-title-link')));
    }
  }
}

jeebsuk’s picture

Is this liable to be added into a new release of the module at some point soon?

ngmaloney’s picture

Assigned: Unassigned » ngmaloney

Yes. I'll test and add today. Thanks for all the contributions!

ngmaloney’s picture

Version: 6.x-1.4 »
Status: Active » Needs review

I added the code from comment #4 @nevets to the block_titlelink 6.x-1.x-dev release. I could use some help testing.

Thanks again for all the contributions!

jeebsuk’s picture

I would happily help you test it, but couldn't find where to download the dev version, only the fully released module is listed on the module page

jeebsuk’s picture

Hi,

I got the module. It is not saving the path when I submit the block form with a path specified for the link, if I return to the block edit form the path field is empty.

ngmaloney’s picture

@JeebsUK thanks for the feedback! I'll get that fixed asap.

ngmaloney’s picture

@JeebsUK: I'm not able to replicate using the Head release from CVS. Could you walk me through the steps to replicate the bug?

jeebsuk’s picture

Hi there,

I downloaded the latest release from the view all releases pages and installed it. I tried to set a path of "forum" for the active forum topics block but when the block form is saved it does not save the path and the title is not a link or clickable.

ngmaloney’s picture

@JeebsUK - OK Thanks for the info. I don't think there is a downloadable release from the latest CVS HEAD. I'll go ahead and add one. In the mean time, if you are familiar with CVS you can checkout the latest HEAD release and it should work.

ngmaloney’s picture

Status: Needs review » Closed (fixed)

Resolved in 6-1.5