How add extra functions to models to never lost updates when fabrik is upgraded

Status
Not open for further replies.

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!
 
Thank you achartier!

Could you override a class of fabrik? Because I tried with the class mentioned and the code breaks in this block:

// MVC factory not found or can't be overridden.
if (!$container->has(MVCFactoryInterface::class) || $container->isProtected(MVCFactoryInterface::class))
{
return;
}

But when I try with com_content the code works well. I noticed that the fabrik4 does not have the new structure of a joomla4 component, like to use namespaces, this impact in anything?
 
You should be able to override just about any class. Make sure this plugin is at the top of the list so it gets executed first.
 
I gave you bad information. This plugin will not work with the current version of Fabrik as the codebase is not purely J4. Having said that, you might be able to get the older version to work for you. https://github.com/gruz/MVC-Override I have not tested this one in quite some time so I make no guarantees.
 
Thank you very much!

Unfortunately this new MVC Override plugin only works with joomla 3, but knowing that this version of fabrik does not support override, I will wait for joomla5 and the official fabrik5 to implement this plugin in my work.
In general, worked for com_content, so I got what I wanted.
 
Don't hold your breath for F5. It is a long way out and a great amount of work left to do on it. The current F4 will get us through J4 & J5. Hopefully by the time J6 rolls around we will have F5 (probably renamed to F6) available, but no guarantee on timing or functionality. The Fabrik codebase is bigger than Joomla.
 
Status
Not open for further replies.
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top