0

I am in the process to cleanup the code of my extensions to fit the requirements for the joomla4 API.
Unfortunately there are no migration documentations available to support this effort. I also could not find any refrences or implementations with the current joomla4 code. If you look into this code you will find mostly the use of depecated (old) methods. Also searching the web did not help either. Would be fine if someone could help with some hints - especially with this topic below:

Create a controller instance version 3.0 API:

$controller = BaseController::getInstance($prefix);

I get a hint for the deprecated "getInstance":

Joomla\CMS\MVC\Controller\BaseController::getInstance(string $prefix, array $config=[]) : static Deprecated. 5.0 Get the controller through the MVCFactory instead

Unfortunately there are no docs nor any samples how to create my controller via MVCFactory - can somebody help with this issue?

Jochen
  • 1
  • 1

1 Answers1

0

Short answer

Removing all deprecated code in order to migrate to Joomla 4 is not necessary. According to joomla.org announcement on Joomla 5 no deprecated code will be removed in Joomla 5.0, so we have at least till Joomla 6.0 until this code get removed.

Long answer

The original plans to remove deprecated code in Joomla 5 as announced were abandoned. Deprecated code annotations where finally improved in Joomla 4.3 including small examples which statement(s) to use instead. In your case for BaseController:

 /**
 * Method to get a singleton controller instance.
 *
 [...]
 *
 * @deprecated  4.3 will be removed in 6.0
 *              Get the controller through the MVCFactory instead
 *              Example: Factory::getApplication()->bootComponent($option)->getMVCFactory()->createController(...);
 *
 * @throws      \Exception if the controller cannot be loaded.
 */
public static function getInstance($prefix, $config = [])

As far as I know the solution does not work with legacy components, since the createController() method in Joomla\CMS\MVC\Factory\LegacyFactory (J5-dev) doesn't (and probably won't) support the creation of legacy controllers:

public function createController($name, $prefix, array $config, CMSApplicationInterface $app, Input $input)
{
    throw new \BadFunctionCallException('Legacy controller creation not supported.');
}

So cleaning up the calls to

$controller = BaseController::getInstance($prefix);

will be on the list for Joomla 6 migration.

For Tables, Models and Views the new code examples from the comments (since Joomla 4.3) do work also with legacy extensions.

Dave
  • 1
  • 1