Hi all,

Thank you for this fantastic module.

I've noticed that if the URL of the link contains parametrs, the resulting URL is not encoded properly, resulting in a broken link.

(e.g. this URL breaks: news?field_cat_new_tid_i18n[0]=1)

This is because parameters aren't processed accordingly in the l() function when preprocessing the block.

I think this is a major issue.

I wrote a quick workaround patch:

line 126 - function block_titlelink_preprocess_block - block_titlelink.module

		//Separate parameters
		$url = explode('?', $vars['block']->title_link);
		
		if (isset($url[1])) {
			$attributes['query'] = array();
			$params = explode('&', $url[1]);			
			foreach($params as $p) {
				//Update attributes array with corresponding params
				$auxParam = explode('=', $p);
				$attributes['query'][$auxParam[0]] = $auxParam[1];
			}
		}
CommentFileSizeAuthor
#1 block_titlelink-1681204-2.patch2.48 KBautopoietic

Comments

autopoietic’s picture

StatusFileSize
new2.48 KB

I also needed to have query strings on block title links, in my case so that the link would configure exposed filters on a view.

I have created the attached patch similarly to @bmunslow but instead of breaking off the querystring into parameters in the preprocess function I opted to do this in the submit handler and save the querystring array separately.

The patch works for me anyway.

autopoietic’s picture

Status: Active » Needs review
adammalone’s picture

Thanks - I think I'll use drupal_parse_url on this.

adammalone’s picture

Assigned: Unassigned » adammalone
Status: Needs review » Active

This code will be committed soon - if people have thoughts or additional extras it can be discussed here:

      // Allow Drupal to parse the URL and provide us with a keyed array
      // that we can hand off to l()
      $parsed_url = drupal_parse_url($vars['block']->title_link);

      // Add in the query string if one exists.
      if (!empty($parsed_url['query'])) {
        $attributes['query'] = $parsed_url['query'];
      }
      // Build the fragment onto the end if it is present.
      if (!empty($parsed_url['fragment'])) {
        $attributes['fragment'] = $parsed_url['fragment'];
      }

      $vars['block']->subject = l(t($vars['block']->subject), $parsed_url['path'], $attributes);
drupalpal’s picture

This not pushed to the latest dev or stable release? right?

I had to add it manually....

adammalone’s picture

Title: Parametrs in link not encoded correctly » Parameters in link not encoded correctly
Assigned: adammalone » Unassigned
Status: Active » Fixed

Pushed to latest dev, thanks!

Status: Fixed » Closed (fixed)

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