The following example module demonstrates how to turn text that appears in changelist, job, or code review descriptions, comments, and activity entries into links.
Rickroll
in the module folder.Create the file Module.php
within module/Rickroll
and edit it to contain:
<?php
/**
* Helix Swarm
*
* @copyright 2014 Perforce Software. All rights reserved.
* @license Please see LICENSE.txt in top-level folder of this distribution.
* @version <release>/<patch>
*/
namespace Rickroll;
use Application\Filter\Linkify;
class Module
{
public function onBootstrap()
{
Linkify::addCallback(
function ($value, $escaper) {
if (strcasecmp($value, 'rickroll')) {
// not a hit; tell caller we did not handle this one
return false;
}
return '<a target="_new" href="https://www.youtube.com/watch?v=dQw4w9WgXcQ">'
. $escaper->escapeHtml($value) . "</a>";
},
'rickroll',
strlen('rickroll')
);
}
public function getConfig()
{
return array();
}
}
This file achieves several things. It:
Rickroll
folder a recognized module.Rickroll
.onBootstrap()
method that allows the module's configuration to be established immediately after the module is loadedrickroll
) and, when found, how to compose the link for that text.