预先声明下,本文内容比较小众,需要有较丰富开发经验才可看懂;初学者可以跳过。
对于feature重度用户来说,每次使用手工方式点击导出features并进行代码覆盖的方式,显然是很低效的做法。
好消息是,features提供对drush的支持,可以通过如下命令进行查看相关命令:
drush |grep features
支持的命令列表如下:
features-add (fa) Add a component to a feature module. (DEPRECATED: use features-export)
features-components List features components.
features-diff (fd) Show the difference between the default and overridden state of a feature.
features-diff-all Show the code difference for all enabled features not in their default state.
features-export (fe) Export a feature from your site into a module.
features-list (fl, List all the available features for your site.
features)
features-revert (fr) Revert a feature module on your site.
features-revert-all Revert all enabled feature module on your site.
features-update (fu) Update a feature module on your site.
features-update-all Update all feature modules on your site.
我比较常用的是drush fu命令,一般情况下,比较省心;但是对于多语言项目,而且默认语言为非英文的,有时候会导致一定的问题。
这个问题就是,在features界面下,导出的features有些内容是英文的,但是使用drush fu命令导出的命令,使用的是站点默认语言。
截图如下:
这种如果项目如果使用了版本控制工具,如git,svn等,比较蛋疼--你究竟是提交呢,还是不提交呢?
下面的代码,将drush执行语言环境都设定为英文,避免了该问题的产生。亲测可行。
/** * Implement hook_lanuage_init(). */ function hook_language_init() { if (function_exists('drush_main')) { global $language; $languages = language_list(); $language = $languages['en']; } }
更新与2015年10月8日:
后来,我在官网上搜到了相关讨论,已经解决了该问题;本文则继续保留,作为一个解决问题的参考。
https://www.drupal.org/node/1988252
主要使用features的2.x-dev版本即可。