Extending the Core library?

Floren

Well-known member
Hi guys,

I did not deeped into Xen code properly, so I will ask the question here.
What is the proper way to extend the XenForo_Template_Helper_Core class?

Thanks.
 
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 :)
 
xfrokcs, I was looking for this the other day. Now to turn trombone13's custom add-on into an actual add-on with no code edits! (probably still templates. haha)
 
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 :)
That's exactly what I do. :)
PHP:
/**
* 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')
		)
	);
}
 
OK, I'm back at this. So, all I have to do is call it with an init_dependencies, right?
I used that listener and the code is working half way:
Code:
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
	}
}

I only get a var_dump on helperUserTitle, the helperBbCode event does nothing...
 
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:

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
	}
}
Try that instead and see if you have more luck. If that doesn't work, I'm going to need more info.

Bear in mind that the bbcode helper there is used very very infrequently - we do almost all of our bbcode parsing in View.
 
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:

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
}
}
Try that instead and see if you have more luck. If that doesn't work, I'm going to need more info.

Bear in mind that the bbcode helper there is used very very infrequently - we do almost all of our bbcode parsing in View.


What about if we are trying to extend the XenForo_Template_Compiler? There is no static var so we can add our own tags.
 
AFAIK there is ATM no way to extend it
Until now there is still no way to extend core helper?
I've tried this but it didn't work
PHP:
<?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;
    }
}
?>
 
Top Bottom