diego_godina
New Member
Hi everyone,
My doupt is how and if I can add extra functions to models class like PlgFabrik_Element (components/com_fabrik/models/element.php) to never lost when fabrik update happens. Because in fabrik 3.10, I changed the databasejoin plugin and nedded some functions inside the class above, but now when I update to fabrik4 I lost them.
I reasearch about this and I found one way, but I dont know if is the best way to do this and does not work yet. Building a system plugin and using the event onAfterExtensionBoot. The code of php file:
<?php
// No direct access
defined('_JEXEC') or die('Restricted access');
use Joomla\CMS\Language\Text;
use Joomla\Registry\Registry;
use Joomla\CMS\MVC\Model\BaseDatabaseModel;
use Joomla\CMS\Table\Table;
use Joomla\CMS\Table\Extension;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\CMS\Version;
use Joomla\CMS\Date\Date;
use Joomla\CMS\Form\Form;
use Joomla\CMS\Factory;
use Joomla\CMS\Filesystem\File;
use Joomla\Utilities\ArrayHelper;
use Fabrik\Helpers\Worker;
jimport('joomla.plugin.plugin');
jimport('joomla.filesystem.file');
/**
* Extension Fabrik of system
*
* @package Joomla.Plugin
* @subpackage System
* @since 1.0
*/
class PlgSystemExtdatabrik extends CMSPlugin
{
/**
* Constructor
*
* @param object &$subject The object to observe
* @param array $config An array that holds the plugin configuration
*
* @since 1.0
*/
public function __construct(&$subject, $config)
{
}
/**
* When the extensions were initialize this event will be trigger
*
* @param object Event generated
*
* @since 1.0
*/
public static function onAfterExtensionBoot(\Joomla\Event\EventInterface $event)
{
if ($event->getArgument('type') !== 'Joomla\\CMS\\Extension\\ComponentInterface') {
return;
}
if ($event->getArgument('extensionName') !== 'fabrik') {
return;
}
$container = $event->getArgument('container');
if (!($container instanceof \Joomla\DI\Container)) {
return;
}
$app = Factory::getApplication();
$db = Factory::getDbo();
$new_file = JPATH_PLUGINS . '/system/extdatabrik/extra/com_' . $event->getArgument('extensionName') . '/element.php';
if (file_exists($new_file)) {
$class = 'Joomla\CMS\Extension\ComponentInterface';
if (!$container->has($class) || $container->isProtected($class)) {
return;
}
require_once $new_file;
$dispatcher = JFactory::getApplication()->getDispatcher();
$container = $container->get($class);
$container->setCategoryFactory($class, new PlgFabrik_ElementExtdatabrik($dispatcher));
}
}
}
If anyone give me help with the code or another way to do this I will be grateful!
My doupt is how and if I can add extra functions to models class like PlgFabrik_Element (components/com_fabrik/models/element.php) to never lost when fabrik update happens. Because in fabrik 3.10, I changed the databasejoin plugin and nedded some functions inside the class above, but now when I update to fabrik4 I lost them.
I reasearch about this and I found one way, but I dont know if is the best way to do this and does not work yet. Building a system plugin and using the event onAfterExtensionBoot. The code of php file:
<?php
// No direct access
defined('_JEXEC') or die('Restricted access');
use Joomla\CMS\Language\Text;
use Joomla\Registry\Registry;
use Joomla\CMS\MVC\Model\BaseDatabaseModel;
use Joomla\CMS\Table\Table;
use Joomla\CMS\Table\Extension;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\CMS\Version;
use Joomla\CMS\Date\Date;
use Joomla\CMS\Form\Form;
use Joomla\CMS\Factory;
use Joomla\CMS\Filesystem\File;
use Joomla\Utilities\ArrayHelper;
use Fabrik\Helpers\Worker;
jimport('joomla.plugin.plugin');
jimport('joomla.filesystem.file');
/**
* Extension Fabrik of system
*
* @package Joomla.Plugin
* @subpackage System
* @since 1.0
*/
class PlgSystemExtdatabrik extends CMSPlugin
{
/**
* Constructor
*
* @param object &$subject The object to observe
* @param array $config An array that holds the plugin configuration
*
* @since 1.0
*/
public function __construct(&$subject, $config)
{
}
/**
* When the extensions were initialize this event will be trigger
*
* @param object Event generated
*
* @since 1.0
*/
public static function onAfterExtensionBoot(\Joomla\Event\EventInterface $event)
{
if ($event->getArgument('type') !== 'Joomla\\CMS\\Extension\\ComponentInterface') {
return;
}
if ($event->getArgument('extensionName') !== 'fabrik') {
return;
}
$container = $event->getArgument('container');
if (!($container instanceof \Joomla\DI\Container)) {
return;
}
$app = Factory::getApplication();
$db = Factory::getDbo();
$new_file = JPATH_PLUGINS . '/system/extdatabrik/extra/com_' . $event->getArgument('extensionName') . '/element.php';
if (file_exists($new_file)) {
$class = 'Joomla\CMS\Extension\ComponentInterface';
if (!$container->has($class) || $container->isProtected($class)) {
return;
}
require_once $new_file;
$dispatcher = JFactory::getApplication()->getDispatcher();
$container = $container->get($class);
$container->setCategoryFactory($class, new PlgFabrik_ElementExtdatabrik($dispatcher));
}
}
}
If anyone give me help with the code or another way to do this I will be grateful!