Skip to content

Commit

Permalink
[4.0] [MVC] Always set model/view prefix, correct base path detection (
Browse files Browse the repository at this point in the history
  • Loading branch information
SharkyKZ authored and wilsonge committed Jul 23, 2019
1 parent df3a965 commit ba2c285
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 26 deletions.
42 changes: 28 additions & 14 deletions libraries/src/MVC/Controller/BaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -580,11 +580,6 @@ protected function checkEditId($context, $id)
*/
protected function createModel($name, $prefix = '', $config = array())
{
if (!$prefix)
{
$prefix = $this->app->getName();
}

$model = $this->factory->createModel($name, $prefix, $config);

if ($model === null)
Expand Down Expand Up @@ -615,11 +610,6 @@ protected function createModel($name, $prefix = '', $config = array())
*/
protected function createView($name, $prefix = '', $type = '', $config = array())
{
if (!$prefix)
{
$prefix = $this->app->getName();
}

$config['paths'] = $this->paths['view'];

return $this->factory->createView($name, $prefix, $type, $config);
Expand Down Expand Up @@ -756,9 +746,21 @@ public function getModel($name = '', $prefix = '', $config = array())
$name = $this->getName();
}

if (empty($prefix) && $this->factory instanceof LegacyFactory)
if (!$prefix)
{
$prefix = $this->model_prefix;
if ($this->factory instanceof LegacyFactory)
{
$prefix = $this->model_prefix;
}
// When the frontend uses an administrator model
elseif (!empty($config['base_path']) && strpos(Path::clean($config['base_path']), JPATH_ADMINISTRATOR) === 0)
{
$prefix = 'Administrator';
}
else
{
$prefix = $this->app->getName();
}
}

if ($model = $this->createModel($name, $prefix, $config))
Expand Down Expand Up @@ -866,9 +868,21 @@ public function getView($name = '', $type = '', $prefix = '', $config = array())
$name = $this->getName();
}

if (empty($prefix) && $this->factory instanceof LegacyFactory)
if (!$prefix)
{
$prefix = $this->getName() . 'View';
if ($this->factory instanceof LegacyFactory)
{
$prefix = $this->getName() . 'View';
}
// When the front uses an administrator view
elseif (!empty($config['base_path']) && strpos(Path::clean($config['base_path']), JPATH_ADMINISTRATOR) === 0)
{
$prefix = 'Administrator';
}
else
{
$prefix = $this->app->getName();
}
}

if (empty(self::$views[$name][$type][$prefix]))
Expand Down
12 changes: 0 additions & 12 deletions libraries/src/MVC/Factory/MVCFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,6 @@ public function createModel($name, $prefix = '', array $config = [])
$name = preg_replace('/[^A-Z0-9_]/i', '', $name);
$prefix = preg_replace('/[^A-Z0-9_]/i', '', $prefix);

// When the front uses a back end model
if (!$prefix && !empty($config['base_path']) && strpos($config['base_path'], '/administrator/') !== false)
{
$prefix = 'Administrator';
}

if (!$prefix)
{
@trigger_error(
Expand Down Expand Up @@ -150,12 +144,6 @@ public function createView($name, $prefix = '', $type = '', array $config = [])
$prefix = preg_replace('/[^A-Z0-9_]/i', '', $prefix);
$type = preg_replace('/[^A-Z0-9_]/i', '', $type);

// When the front uses a back end view
if (!$prefix && !empty($config['base_path']) && strpos($config['base_path'], '/administrator/') !== false)
{
$prefix = 'Administrator';
}

if (!$prefix)
{
@trigger_error(
Expand Down

0 comments on commit ba2c285

Please sign in to comment.