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

查看:26
本文介绍了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天全站免登陆