For extension Developers: How to use in your extension
The PHP event from this extension to set topic prefix tags, looks like this:
Code: Select all
/**
* Event to set topic prefix tags
*
* @event
* @var int topic_id changing won't be fed back to calling event
* @var array topic_data changing won't be fed back to calling event
* @var string origin_event_name the name of the original event
* @var array tags push here your tags
*
*/
$vars = ['topic_id', 'topic_data', 'origin_event_name', 'tags'];
$result = $this->dispatcher->trigger_event('marttiphpbb.topicprefixtags', compact($vars));
The sister extension,
Topic Suffix Tags (helper ext), triggers a PHP event that works entirely the same way. You could add listeners for both extensions in your extension to provide your users (admins) flexibility so they can choose whether they want your data be displayed as a prefix or a suffix.
The example in the screenshots, just showing the topic id was implemented like this in the listener:
Code: Select all
static public function getSubscribedEvents()
{
return [
'marttiphpbb.topicprefixtags' =>
'marttiphpbb_topicprefixtags',
];
}
public function marttiphpbb_topicprefixtags($event)
{
$tags = $event['tags'];
$topic_id = $event['topic_id'];
$tags[] = '[*' . $topic_id . '*]';
$event['tags'] = $tags;
}
The values pushed to the
$tags
array can be:
- a string, which will be rendered "raw", so you can include html tags if you like.
- an array itself, with keys
include
and var
In case of b:
include
is a string of a template file to be included from your extension, so prefix it with
@vendor_myextension/
var
can be both a string or an array for providing variables to the included template. (
var
is the only variable available)
Example of a template:
Code: Select all
[ <a href="{{- var.url -}}"></a><i class="fa fa-pencil"></i> {{ lang('LANG_KEY', var.lang) -}}</a> ]