For example I want to modify the link per user, so I can provide a code in my module which will create the link.

Another option is to use tokens.

Comments

ngmaloney’s picture

Assigned: Unassigned » ngmaloney
Status: Active » Postponed

Will look into feasibility of implementing on next release.

alexbk66-’s picture

Thank you @ngmaloney

alexbk66-’s picture

Title: Would be nice to have PHP supported » Would be nice to have PHP and/or tokens supported

Changing title

alexbk66-’s picture

I implemented the token support, as I don't know how to create patches (yet), just posting my changes here

/**
 * Implementation of hook_preprocess_block
**/
function block_titlelink_preprocess_block(&$vars, $hook) {
  if ($hook == 'block') {
    $vars['block']->title_link = _block_titlelink_get_link($vars['block']);
    $title_link = $vars['block']->title_link;
    if ($title_link != '') {
      if (function_exists('token_replace')) {
        $title_link = token_replace($title_link);
      }
      $vars['block']->subject = l($vars['block']->subject, $title_link, array('attributes' => array('class' => 'block-title-link'), 'html'=>'true'));
    }
  }
}

And to display the list of available tokens on block config form:

/**
 * Implementation of hook_form_alter
**/
function block_titlelink_form_alter(&$form, &$form_state, $form_id) {
  .
  .
  .
    $description = t('URL for Block Title to link to.');
    if(function_exists('token_get_values')) {
      $description .= t(' Available tokens: ') . theme('token_tree', array('global'), TRUE, FALSE);
    }
    
    $form['block_titlelink']['title_path'] = array(
      '#type' => 'textfield',
      '#title' => t('Title Path'),
      '#default_value' => $link,
      '#description' => $description,
    );

   $form['#validate'][] = 'block_titlelink_validate';
  }
}

ngmaloney’s picture

Status: Postponed » Needs review

Thanks for posting @alexbk66. Will review and test. If everything works I'll integrate with -dev branch.

alexbk66-’s picture

If change last argument to TRUE, than can click on token to insert in text field:

theme('token_tree', array('global'), TRUE, TRUE);

Because only global tokens are available, the list of tokens isn't collapsed, so it takes a lot of space on the form, but I couldn't find how to collapse it by default.

alexbk66-’s picture

And here's PHP support:


/**
 * Implementation of hook_preprocess_block
**/
function block_titlelink_preprocess_block(&$vars, $hook) {
  if ($hook == 'block') {
    $vars['block']->title_link = _block_titlelink_get_link($vars['block']);
    $title_link = $vars['block']->title_link;
    if ($title_link != '') {
    
      $title_link_php = drupal_eval($title_link);
      if($title_link_php) {
        $title_link = $title_link_php;
      }
      if (function_exists('token_replace')) {
        $title_link = token_replace($title_link);
      }

      $vars['block']->subject = l($vars['block']->subject, $title_link, array('attributes' => array('class' => 'block-title-link'), 'html'=>'true'));
    }
  }
}
adammalone’s picture

Assigned: ngmaloney » adammalone
Status: Needs review » Active

Just to keep this alive and on my radar, I'm going to backport the latest D7 release with PHP and token support into a new branch of the D6 version. Watch this space!

Patch files are also greeted with <3

adammalone’s picture

Status: Active » Needs review

Check out the 6.x-2.x branch for these features.

adammalone’s picture

Version: 6.x-1.7 » 6.x-2.0
Status: Needs review » Fixed

Fixed in 6.x-2.0

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.