对于 com_media 覆盖,我解决此问题的一种方法是创建一个带有 onAfterRoute() 事件处理程序的系统插件,以捕获和评估请求 URL 参数。然后我可以设置模板覆盖路径并为我的视图和模板使用包含。我在 /plugins/system/mycommedia/mycommedia.php 中的示例系统插件代码,
// no direct access
defined ( '_JEXEC' ) or die ( 'Restricted access' );
jimport('joomla.plugin.plugin');
class plgSystemMyComMedia extends JPlugin {
public function onAfterRoute() {
if('com_media' == JRequest::getCMD('option')) {
$view = JRequest::getCMD('view');
if (('images' == $view) || ('imageslist' == $view)) {
$overridePath = FOFPlatform::getInstance()->getTemplateOverridePath('com_media', true) . '/' . $view;
require_once $overridePath . '/view.html.php';
}
}
}
}
上面的这个版本的 onAfterRoute() 函数展示了如何为后端(管理员)视图和模板应用覆盖。
public function onAfterRoute() {
$app = JFactory::getApplication();
if ($app->isAdmin()) {
if('com_media' == JRequest::getCMD('option')) {
$view = JRequest::getCMD('view');
if (('images' == $view) || ('imageslist' == $view)) {
$overridePath = FOFPlatform::getInstance()->getTemplateOverridePath('com_media', true) . '/' . $view;
require_once $overridePath . '/view.html.php';
}
}
}
}
通过从 com_media 组件复制到您的模板文件夹来创建新的自定义模板和视图。例如,如果您想为您的管理员 isis 模板自定义媒体管理器:
复制
/administrator/components/com_media/views/images
到
/administrator/templates/isis/html/com_media/images
复制
/administrator/components/com_media/views/imageslist
到
/administrator/templates/isis/html/com_media/imageslist
然后修改 view.html.php 的两个副本以包含它们各自的默认模板副本。
在显示函数的最后,注释掉或者替换,
parent::display($tpl);
在模板副本中包含指令,
include( dirname(__FILE__) . '/tmpl/default.php');
还要注释或替换 imageslist 默认模板中的 loadTemplate('folder') 和 loadTemplate('image') 函数调用,以包含它们各自的文件和文件夹默认模板副本。
例如,在 /administrator/templates/isis/html/com_media/imageslist/tmpl/default.php 中
<?php for ($i = 0, $n = count($this->folders); $i < $n; $i++) :
$this->setFolder($i);
//echo $this->loadTemplate('folder');
include( dirname(__FILE__) . '/default_folder.php');
endfor; ?>
<?php for ($i = 0, $n = count($this->images); $i < $n; $i++) :
$this->setImage($i);
//echo $this->loadTemplate('image');
include( dirname(__FILE__) . '/default_image.php');
endfor; ?>
com_media 视图和模板现在将被加载而不是它们的核心对应物,并且可以在不破解任何核心 Joomla 文件的情况下进行自定义。
更多信息@http://jimfrenette.com/joomla/customizing-joomla-media-manager/