Drupal 6:更改贡献模块的JavaScript的最佳实践 [英] Drupal 6: best practice for changing contributed module's JavaScript

查看:51
本文介绍了Drupal 6:更改贡献模块的JavaScript的最佳实践的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个有关如何自定义drupal模块以避免黑客攻击的问题。

I've a question about how to customize drupal modules avoiding hacks.

假设我已经下载了Lightbox2模块,并且想更改要显示的javascript文件

Let's say I've downloaded Lightbox2 module and I want to change the javascript file to display differently my lightbox.

此刻,我正在修改Lightbox2模块,因此我无法再对其进行更新,所以我知道这不是最佳实践。

At the moment I'm modifying the Lightbox2 module, so I cannot update it anymore, so I know it is not the best practice.

我想知道是否可以使用钩子自定义该模块的javascript文件,以及如何自定义。

I was wondering if I can customize the javascript file of this module with a hook, and how.

谢谢

推荐答案

仅更改JS,就根本不需要修改模块。相反,您可以使用主题系统来更改发送到页面的脚本。

To alter just the JS, you shouldn't need to hack the module at all. Instead, you can use the theme system to alter what scripts are sent to the page.

在template.php预处理页面中:

In your template.php preprocess page:

 $scripts = drupal_add_js();
 unset($scripts['module']['whatever/the/path/is/lightbox.js']);
 $scripts['module']['new/js/path/lightbox.js'] = array('preprocess' => 1, 'cache' => 1);
 $variables['scripts'] = drupal_get_js('header', $scripts);

我建议您然后跨灯箱JS复制到新路径并在那里进行更改,而不是开始从头开始。

I suggest you then copy across the lightbox js to new path and make your alterations there, rather than starting from scratch.

某些模块提供了自己的钩子和主题函数,您可以直接重写它们,因此对于那些灯箱模块来说也值得一试。

Some modules provide their own hooks and theme functions which you can override directly, so it might be worth poking around a bit in the lightbox module for those too.

这篇关于Drupal 6:更改贡献模块的JavaScript的最佳实践的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆