Example linkify module
The following example module demonstrates how to turn text that appears in changelist or code review descriptions, comments, and activity entries into links.
-
Create a folder called Shedanigans in the module folder.
-
Create the file
Module.php
withinmodule/Shedanigans
and edit it to contain:<?php /** * Perforce Swarm * * @copyright 2014 Perforce Software. All rights reserved. * @license Please see LICENSE.txt in top-level folder of this distribution. * @version <release>/<patch> */ namespace Shedanigans; use Application\Filter\Linkify; class Module { public function onBootstrap() { Linkify::addCallback( function ($value, $escaper) { if (strcasecmp($value, 'shedanigans')) { // not a hit; tell caller we didn't handle this one return false; } return '<a target="_new" href="http://shedanigans.com/">' . $escaper->escapeHtml($value) . "</a>"; }, 'shedanigans', strlen('shedanigans') ); } public function getConfig() { return array(); } }
This file achieves several things. It:
-
makes the
Shedanigans
folder a recognized module. -
declares the module's namespace, which matches the module's folder name
Shedanigans
. -
provides an
onBootstrap()
method that allows the module's configuration to be established immediately after the module is loaded -
Adds a callback to the Linkify module that declares what text is to be searched for and, when found, how to compose the link for that text.
-