Drupal 6: best practice for changing contributed module's JavaScript

六月ゝ 毕业季﹏ 提交于 2019-12-08 05:00:55

问题


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

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

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

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

Thanks


回答1:


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.

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);

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.



来源:https://stackoverflow.com/questions/3051765/drupal-6-best-practice-for-changing-contributed-modules-javascript

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!