1

In my provider.php I have this:

function (Container $container) {                    
       $dispatcher = $container->get(DispatcherInterface::class);
       $config = (array) PluginHelper::getPlugin('system', 'autbox');

       $plugin = new Autbox($dispatcher, $config);
       $plugin->setApplication(Factory::getApplication());

       return $plugin;
}

In my Autbox constructor I instantiate an object $this->objBox. In this plugin I have several custom fields... It is possible access $this->objBox from these custom fields?

Many thanks

1 Answer 1

2

There's currently no sensible way to inject dependencies into form elements, even with a custom form factory as described in How to override J5 library classes. It's possible, just not worth the effort considering that you'd need to use either some ugly hacks or duplicate lots of code. So for the time being you can boot the plugin through the application directly within the custom field:

use Joomla\CMS\Factory;

$plugin = Factory::getApplication()->bootPlugin('autbox', 'system');
$var = $plugin->objBox;
1
  • Yes, I finally solved it this way. Although I don't like the solution very much, I think you are right when you write that, for now, it is the only reasonable decent solution. Commented Feb 27 at 10:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.