Custom template types

www

New member
Affected version
2.3.3
Creating custom template types (\XF\Entity\Template::$type) through add-ons seems to be problematic during upgrades, as the importer seems to adhere to the structure's allowedValues (expecting either mail, admin, or public), throughout which add-on class extensions have yet to take effect.

To reproduce this, start by extending \XF\Entity\Template to allow for the new custom template type.
PHP:
<?php

namespace AddOn\XF\Entity;

class Template extends XFCP_Template
{
    #[\Override]
    public static function getStructure(\XF\Mvc\Entity\Structure $structure)
    {
        $structure = parent::getStructure($structure);

        $structure->columns['type']['allowedValues'][] = 'custom';

        return $structure;
    }
}

Next, extend \XF\Repository\TemplateRepository to show the new custom type in the ACP templates section.
PHP:
<?php

namespace AddOn\XF\Repository;

class TemplateRepository extends XFCP_TemplateRepository
{
    #[\Override]
    public function getTemplateTypes(\XF\Entity\Style $style = null)
    {
        $types = parent::getTemplateTypes($style);

        $types['custom'] = \XF::phrase('addon_custom');

        return $types;
    }
}

Then, create a new custom template through the ACP, e.g.
[...]/admin.php?templates/add&style_id=0&type=custom

While everything seems to be fine thus far, the following add-on installation/upgrade will fail to do so, as the new custom type will be considered invalid during the template import process.

Server error log​

XF\PrintableException: Batch install error: Please enter a valid value. • src/XF/Mvc/Entity/Entity.php:1270

Stack trace​

Code:
#0 src/XF/AddOn/DataType/Template.php(98): XF\Mvc\Entity\Entity->save(true, false)
#1 src/XF/Job/AddOnData.php(112): XF\AddOn\DataType\Template->importAddOnData('AddOn', Object(SimpleXMLElement), 0, 7.9929)
#2 src/XF/Job/AddOnInstallBatch.php(345): XF\Job\AddOnData->run(7.9929)
#3 src/XF/Job/AddOnInstallBatch.php(99): XF\Job\AddOnInstallBatch->stepData(Object(XF\Timer))
#4 src/XF/Job/Manager.php(275): XF\Job\AddOnInstallBatch->run(8)
#5 src/XF/Job/Manager.php(205): XF\Job\Manager->runJobInternal(Array, 8)
#6 src/XF/Job/Manager.php(121): XF\Job\Manager->runJobEntry(Array, 8)
#7 src/XF/Admin/Controller/ToolsController.php(146): XF\Job\Manager->runByIds(Array, 8)
#8 src/XF/Mvc/Dispatcher.php(362): XF\Admin\Controller\ToolsController->actionRunJob(Object(XF\Mvc\ParameterBag))
#9 src/XF/Mvc/Dispatcher.php(264): XF\Mvc\Dispatcher->dispatchClass('XF:Tools', 'RunJob', Object(XF\Mvc\RouteMatch), Object(XF\Admin\Controller\ToolsController), NULL)
#10 src/XF/Mvc/Dispatcher.php(121): XF\Mvc\Dispatcher->dispatchFromMatch(Object(XF\Mvc\RouteMatch), Object(XF\Admin\Controller\ToolsController), NULL)
#11 src/XF/Mvc/Dispatcher.php(63): XF\Mvc\Dispatcher->dispatchLoop(Object(XF\Mvc\RouteMatch))
#12 src/XF/App.php(2826): XF\Mvc\Dispatcher->run()
#13 src/XF.php(806): XF\App->run()
#14 admin.php(15): XF::runApp('XF\\Admin\\App')
#15 {main}
 
Last edited:
Back
Top Bottom