You can move and replace existing widgets and templates by declaring
runBuildCacheHandler() method in your Main.php file as follows:
HTML Code:
/**
* This method runs at the end of the cache rebuilding process.
*
* @return void
*/
public static function runBuildCacheHandler()
{
/*
* Items in XLite\Model\ViewList have the following attributes:
* - 'list' - the full identifier of the "view list" in which
* the item is to be displayed
* - 'child' - the full class name of the widget to be displayed
* - 'tpl' - the template file to be displayed (path to the
* file inside the "skins/[skin-name]/[language-id]/" directory)
*/
$item1 = \XLite\Core\Database::getRepo('XLite\Model\ViewList')->findOneBy(
array(
'list' => '[current_view_list]',
'child' => '[widget_class]',
)
);
if ($item1) {
// Now you can move the widget to another "view list"
$item1->setList('[new_view_list]');
// ... or replace it with a custom widget class
$item1->setChild('[custom_widget_class]');
}
$item2 = \XLite\Core\Database::getRepo('XLite\Model\ViewList')->findOneBy(
array(
'list' => '[current_view_list]',
'tpl' => '[relative_path_to_template]',
)
);
if ($item2) {
// Move the template to another "view list"
$item2->setList('[new_view_list]');
// Replace the item with a custom template file
$item2->setTpl('[custom_template_path]');
}
if ($item1 || $item2) {
// Push the changes into the database
\XLite\Core\Database::getEM()->flush();
}
}