XenForo_Template_Helper_Core::$helperCallbacks['myawesomehelperfunciton'] = array('My_Awesome_Helper_Class', 'functionX');
That's exactly what I do.You can add a helper by modify the static property XenForo_Template_Helper_Core::$helperCallbacks in the init_dependencies listener (basically as soon as possible). It's a pubic property so... feel free to add your new helper or modifying the core ones
PHP:XenForo_Template_Helper_Core::$helperCallbacks['myawesomehelperfunciton'] = array('My_Awesome_Helper_Class', 'functionX');
Hope this helps![]()
/**
* Called by a code event to add special helpers to the template helper core
*/
public static function initDependencies()
{
XenForo_Template_Helper_Core::$helperCallbacks = array_merge(
XenForo_Template_Helper_Core::$helperCallbacks, array
(
'photothumb' => array('Thingy_Helper_FileFetch', 'helperPhotoThumb'),
'itemthumb' => array('Thingy_Helper_FileFetch', 'helperItemThumb'),
'video' => array('Thingy_Helper_FileFetch', 'helperVideo')
)
);
}
class Addon_CodeEvent
{
private function __construct()
{}
public static function init()
{
XenForo_Template_Helper_Core::$helperCallbacks = array_merge(
XenForo_Template_Helper_Core::$helperCallbacks, array(
'bbcode' => array('Addon_Template_Helper_Client', 'helperBbCode'),
'usertitle' => array('Addon_Template_Helper_Client', 'helperUserTitle')
)
);
}
}
class Addon_Template_Helper_Client extends XenForo_Template_Helper_Core
{
public static function helperBbCode($parser, $text)
{
var_dump($text);
exit;
// broken
}
public static function helperUserTitle($user, $allowCustomTitle = true)
{
var_dump($user);
exit;
// works
}
}
class Addon_CodeEvent
{
public static function initDependencies()
{
XenForo_Template_Helper_Core::$helperCallbacks['bbcode']
= array('Addon_CodeEvent', 'helperBbCode');
XenForo_Template_Helper_Core::$helperCallbacks['helperUserTitle']
= array('Addon_CodeEvent', 'helperUserTitle');
}
public static function helperBbCode($parser, $text)
{
// do stuff
}
public static function helperUserTitle($user, $allowCustomTitle = true)
{
// do other stuff
}
}
There's no need to formally extend XenForo_Template_Helper_Core with an inheriting class - just add static properties and methods to it from another class:
Try that instead and see if you have more luck. If that doesn't work, I'm going to need more info.PHP:class Addon_CodeEvent { public static function initDependencies() { XenForo_Template_Helper_Core::$helperCallbacks['bbcode'] = array('Addon_CodeEvent', 'helperBbCode'); XenForo_Template_Helper_Core::$helperCallbacks['helperUserTitle'] = array('Addon_CodeEvent', 'helperUserTitle'); } public static function helperBbCode($parser, $text) { // do stuff } public static function helperUserTitle($user, $allowCustomTitle = true) { // do other stuff } }
Bear in mind that the bbcode helper there is used very very infrequently - we do almost all of our bbcode parsing in View.
Until now there is still no way to extend core helper?AFAIK there is ATM no way to extend it
<?php
class Semprot_RegExpCensor_InitDependenciesListener {
public static function init()
{
XenForo_Template_Helper_Core::$helperCallbacks['string']
= array('Semprot_RegExpCensor_InitDependenciesListener', 'customCensorString');
}
public static function customCensorString($string, array $words = null, $censorString = null)
{
// do stuff
$string = str_replace('p', 'q', $string);
return $string;
}
}
?>
We use essential cookies to make this site work, and optional cookies to enhance your experience.