diff --git a/libraries/src/MVC/Controller/BaseController.php b/libraries/src/MVC/Controller/BaseController.php index def3a9833a718..f9aed69d364a5 100644 --- a/libraries/src/MVC/Controller/BaseController.php +++ b/libraries/src/MVC/Controller/BaseController.php @@ -150,6 +150,22 @@ class BaseController extends \JObject * @since 3.4 */ protected static $views; + + /** + * Return the MVCFactoryInterface class only instantiating it if not exist + * + * @return MVCFactoryInterface + * + * @since 3.9 + */ + private function getFactory() { + // Check if MVC factory is initialized + if(is_null($this->factory)) { + $this->factory = new LegacyFactory; + } + + return $this->factory; + } /** * Adds to the stack of model paths in LIFO order. @@ -556,7 +572,7 @@ protected function checkEditId($context, $id) */ protected function createModel($name, $prefix = '', $config = array()) { - $model = $this->factory->createModel($name, $prefix, $config); + $model = $this->getFactory()->createModel($name, $prefix, $config); if ($model === null) { @@ -587,7 +603,7 @@ protected function createModel($name, $prefix = '', $config = array()) protected function createView($name, $prefix = '', $type = '', $config = array()) { $config['paths'] = $this->paths['view']; - return $this->factory->createView($name, $prefix, $type, $config); + return $this->getFactory()->createView($name, $prefix, $type, $config); } /** @@ -1105,3 +1121,4 @@ public function setRedirect($url, $msg = null, $type = null) return $this; } } +