简体   繁体   English

Drupal,有关自定义模块的问题

[英]Drupal, a question about customizing modules

I've just started to create my own modules to make my custom functions such as hook_form_alter() etc... 我刚刚开始创建自己的模块来制作自定义函数,例如hook_form_alter()等。

Now I was actually wondering how can I use custom modules to make small changes to some modules. 现在,我实际上想知道如何使用自定义模块对某些模块进行小的更改。 For example, consider the View module, I want to modify the file: "views-view.tpl.php" .. let's say change the name of the class of this div 例如,考虑使用View模块,我要修改文件:“ views-view.tpl.php” ..假设更改此div的类的名称

...
<div class="view-filters">
      <?php print $exposed; ?>
    </div>

How can I make it without hacking the code ? 如何在不修改代码的情况下做到这一点?

thanks 谢谢

In order to change the CSS class for the .views-filters div, you need to provides an alternate views-view.tpl.php (or views-view--VIEWNAME.tpl.php or views-view--VIEWNAME--DISPLAYID.tpl.php ). 为了更改.views-filters div的CSS类,您需要提供一个备用views-view.tpl.php (或views-view--VIEWNAME.tpl.phpviews-view--VIEWNAME--DISPLAYID.tpl.php )。 This is usually and easily done in the theme . 这通常是很容易在主题中完成的 But if required, it can be done from a module too: 但是,如果需要,也可以从模块中完成:

function YOURMODULE_registry_alter($theme_registry) {
  $originalpath = array_shift($theme_registry['TEMPLATE']['theme paths']);
  $modulepath = drupal_get_path('module', 'YOURMODULE') .'/themes');
  array_unshift($theme_registry['TEMPLATE']['theme paths'], $originalpath, $modulepath);
}

This allow you to place an overriding views-view.tpl.php template file in the themes directory of your module. 这使您可以将覆盖的views-view.tpl.php模板文件放置在模块的主题目录中。 In order for this to work, your feature should have a weight greater than the one of the module providing the overrided template. 为了使此功能起作用,您的功能应具有比提供覆盖模板的模块之一更大的权重。 So in your module install file (YOURMODULE.install) you will have something like 因此,在模块安装文件(YOURMODULE.install)中,您将看到类似

function YOURMODULE_install() {
   db_query("UPDATE {system} SET weight = 10 WHERE name = 'YOURMODULE'");
}

The easiest way to change what tpl is being used for a view is to provide a TPL to the view to use. 更改视图使用的tpl的最简单方法是为视图提供TPL。 If you click on Theme: Information in a view, it will list various ways you can override the output from the entire view down to the field level. 如果单击视图中的主题:信息,它将列出各种方法,您可以覆盖整个视图直至字段级别的输出。

It's rare that you need to edit a contributed module or the core (if that's what you mean by hacking). 很少需要编辑一个贡献模块或核心(如果这就是黑客的意思)。

The answer is yes! 答案是肯定的!

Having said that, some modules are written poorly. 话虽如此,有些模块编写得很差。 If you can't write an interface to it or fork it, you'll need to hack it and submit a patch to the project's issue queue. 如果您无法为其编写接口或将其派生,则需要对其进行破解,然后将补丁提交至项目的发布队列。 Then your changes might be included in the next release. 然后,您的更改可能会包含在下一个版本中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM