А как ты подсаживаешь туда свой MVCFactory?
Вот так работает только в com_content. Тут что по твоему варианту с $name модели, что таким образом с instanceof - одинаково.
$container->extend(
MVCFactoryInterface::class,
fn ($mvcFactory) => new class($mvcFactory, $this->getApplication()) implements MVCFactoryInterface
{
/**
* The MVC factory
*
* @var MVCFactoryInterface
*
* @since 4.0.0
*/
private $mvcFactory;
private $app;
public function __construct(MVCFactoryInterface $mvcFactory, CMSApplicationInterface $app)
{
$this->mvcFactory = $mvcFactory;
$this->app = $app;
}
public function createModel($name, $prefix = '', array $config = [])
{
$model = $this->mvcFactory->createModel($name, $prefix, $config);
// $name = preg_replace('/[^A-Z0-9_]/i', '', $name);
// $prefix = preg_replace('/[^A-Z0-9_]/i', '', $prefix);
//
// if (!$prefix) {
// $prefix = Factory::getApplication()->getName();
// }
if($model instanceof ArticlesModel)
{
$model = new \Joomla\Plugin\System\Wtmulticategories\Model\ArticlesModel($config);
} elseif ($model instanceof ContactCategoryModel)
{
$model = new \Joomla\Plugin\System\Wtmulticategories\Model\CategoryModel($config);
}
$model = $this->addModelDependencies($model);
return $model;
}
protected function addModelDependencies($model)
{
// Не забываем про зависимости модели!
$model->setFormFactory($this->mvcFactory->getFormFactory());
$model->setDispatcher($this->mvcFactory->getDispatcher());
$model->setMVCFactory($this);
$model->setDatabase(Factory::getContainer()->get(DatabaseInterface::class));
return $model;
}
public function createView($name, $prefix = '', $type = '', array $config = [])
{
return $this->mvcFactory->createView($name, $prefix, $config);
}
public function createController($name, $prefix, array $config, CMSApplicationInterface $app, Input $input)
{
return $this->mvcFactory->createController($name, $prefix, $config, $app, $app->getInput());
}
public function createTable($name, $prefix = '', array $config = [])
{
return $this->mvcFactory->createTable($name, $prefix, $config);
}
}
);