Jump to content


Tip: Fix for Linkify (to add custom links to comments/review/changelists)

swarm linkify module comment review

  • Please log in to reply
4 replies to this topic

#1 PeteS

PeteS

    Advanced Member

  • Members
  • PipPipPip
  • 62 posts

Posted 10 February 2015 - 08:01 AM

Some of you may have investigated using Linkify to add custom links based on your particular strings in changelists, reviews & comments. I wanted to add links to our bug site for bug numbers of the form "Bug 1234" or "Fixed 1234", but was having no luck.

According to the code in Application\Filter\Linkify, it was supposed to be possible to see both the current word ("1234") and the previous word ("Bug") to determine if the words matched the desired pattern. This is supposed to be accomplished by adding a 3rd arg ($last) to the callback function:

Linkify::addCallback(
	function ($value, $escaper, $last)

After a bit of digging, I determined that $last was always the same as $value. It turns out there's a bug in the delivered Linkify.php. To get this to work properly, you simply need to make a one word change on line 285 of /opt/perforce/swarm/module/Application/src/Application/Filter/Linkify.php from:

$replace = $callback['callback']($trimmed, $escaper, $last, $baseUrl);
to:
$replace = $callback['callback']($trimmed, $escaper, $lastWord, $baseUrl);

i.e. replacing $last with $lastWord. After making this change, I can now successfully pattern match on the current word ($value) and the previous word ($last).

Enjoy

#2 P4Shimada

P4Shimada

    Advanced Member

  • Members
  • PipPipPip
  • 831 posts

Posted 17 February 2015 - 11:33 PM

Thanks for reporting this fix, Pete, along with the work-around fix. I recall this same thread here being related:

http://forums.perfor...iewchangelists/

Our developers have already logged this bug and have your notes there.  :-)

#3 PeteS

PeteS

    Advanced Member

  • Members
  • PipPipPip
  • 62 posts

Posted 17 February 2015 - 11:39 PM

Glad to be of help.

BTW, your "other post" is just a link back to this one. :)

#4 PeteS

PeteS

    Advanced Member

  • Members
  • PipPipPip
  • 62 posts

Posted 17 August 2015 - 10:08 PM

Note: if anyone upgrades the latest Swarm and has previously corrected /opt/perforce/swarm/module/Application/src/Application/Filter/Linkify.php, the latest revision will overwrite your change and you'll need to re-edit.

Unless of course the kind folks on the Swarm team could add the corresponding change to their next update... Pretty please?

#5 p4kboyd

p4kboyd

    Newbie

  • Members
  • Pip
  • 5 posts

Posted 18 August 2015 - 07:10 PM

Thanks for this tip, Pete. The 2015.3 release of Swarm (coming this fall, after the 2015.2 release later this month) will include your fix.



Also tagged with one or more of these keywords: swarm, linkify, module, comment, review

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users