mazzly
Well-known member
Hi,
We recently started seeing a compatibility problem with our own addon related to some AddonFlare addons, and the "workaround" at the moment is for our addon to set a higher execution order for the Templater extension. This doesn't feel like the correct solution...
I also have a feeling that this was not a problem before we added XF2.1 support to our addon by overriding the class extension in the
The errors can be seen here and here
Okay, so we have:
The class extension is setup normally as
	
	
	
		
	
	
	
		
	
	
	
		
if our event listeners we have:
	
	
	
		
Questions:
1. Is
2. Is
3. Is there some better way to extend the class differently to support XF2.1 / XF2.2 at the same time without needing 2 differently released packages.
				
			We recently started seeing a compatibility problem with our own addon related to some AddonFlare addons, and the "workaround" at the moment is for our addon to set a higher execution order for the Templater extension. This doesn't feel like the correct solution...
I also have a feeling that this was not a problem before we added XF2.1 support to our addon by overriding the class extension in the
app_setup event.The errors can be seen here and here
Okay, so we have:
The class extension is setup normally as
XF\Template\Templater -> MaZ\AMP\XF\Template\Templater under Development settingsTemplater.php:
		PHP:
	
	class Templater extends XFCP_Templater
{
    // All the common functions for XF2.1 / XF2.2 
}
	Templater21.php:
		PHP:
	
	class Templater21 extends Templater
{
    public function renderTemplate($template, array $params = [], $addDefaultParams = true)
    {
        // Same code as in Templater22, but with different func signature
    }
}
}
	Templater22.php:
		PHP:
	
	class Templater22 extends Templater
{
    public function renderTemplate($template, array $params = [], $addDefaultParams = true, ExtensionSet $extensionOverrides = null)
    {
        // Same code as in Templater21, but with different func signature
    }
}
}
	if our event listeners we have:
		PHP:
	
	public static function app_setup(\XF\App $app)
{
    if (\XF::$versionId < 2020000) {
        $templater_class = '\MaZ\AMP\XF\Template\Templater21';
    } else {
        $templater_class = '\MaZ\AMP\XF\Template\Templater22';
    }
    $app->extension()->addClassExtension('\XF\Template\Templater', $templater_class);
}
	Questions:
1. Is
app_setup the correct event to do the class extension "override"2. Is
$app->extension()->addClassExtension() the correct way to override the extension "during runtime"3. Is there some better way to extend the class differently to support XF2.1 / XF2.2 at the same time without needing 2 differently released packages.
			
				Last edited: 
			
		
	
								
								
									
	
								
							
							