Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 25 additions & 14 deletions libraries/src/Plugin/PluginHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,17 @@ abstract class PluginHelper
*/
public static function getLayoutPath($type, $name, $layout = 'default')
{
$templateObj = Factory::getApplication()->getTemplate(true);
$app = Factory::getApplication();

if ($app->isClient('site') || $app->isClient('administrator')) {
$templateObj = $app->getTemplate(true);
} else {
$templateObj = (object) [
'template' => '',
'parent' => '',
];
}

$defaultLayout = $layout;
$template = $templateObj->template;

Expand All @@ -60,25 +70,26 @@ public static function getLayoutPath($type, $name, $layout = 'default')
}

// Build the template and base path for the layout
$tPath = JPATH_THEMES . '/' . $template . '/html/plg_' . $type . '_' . $name . '/' . $layout . '.php';
$iPath = JPATH_THEMES . '/' . $templateObj->parent . '/html/plg_' . $type . '_' . $name . '/' . $layout . '.php';
$bPath = JPATH_PLUGINS . '/' . $type . '/' . $name . '/tmpl/' . $defaultLayout . '.php';
$dPath = JPATH_PLUGINS . '/' . $type . '/' . $name . '/tmpl/default.php';

// If the template has a layout override use it
if (is_file($tPath)) {
return $tPath;
$layoutPaths = [];

if ($template) {
$layoutPaths[] = JPATH_THEMES . '/' . $template . '/html/plg_' . $type . '_' . $name . '/' . $layout . '.php';
}

if (!empty($templateObj->parent) && is_file($iPath)) {
return $iPath;
if ($templateObj->parent) {
$layoutPaths[] = JPATH_THEMES . '/' . $templateObj->parent . '/html/plg_' . $type . '_' . $name . '/' . $layout . '.php';
}

if (is_file($bPath)) {
return $bPath;
$layoutPaths[] = JPATH_PLUGINS . '/' . $type . '/' . $name . '/tmpl/' . $defaultLayout . '.php';
$layoutPaths[] = JPATH_PLUGINS . '/' . $type . '/' . $name . '/tmpl/default.php';

foreach ($layoutPaths as $path) {
if (is_file($path)) {
return $path;
}
}

return $dPath;
return end($layoutPaths);
}

/**
Expand Down