大多数项目似乎在其项目页面、安装说明和 README 文件中清楚地列出了外部库依赖项。如果用户尚未安装所需的库,许多人使用库 API 来包含依赖项并显示配置警告。 CKeditor、colorbox 和 JSON2 都是我想到的例子。
更新
不,库模块不下载依赖项。它只是提供了一个安装位置以及在模块中包含和使用的方法。请参阅库项目页面
安装库模块。在sites/all/libraries安装外部依赖。
首先,使用 hook_libraries_info() 注册库。
/**
* Implements hook_libraries_info().
*/
function mymodule_libraries_info() {
$libraries['anet_php_sdk'] = array(
'name' => 'Authorize.net PHP SDK',
'vendor url' => 'https://developer.authorize.net/',
'download url' => 'http://developer.authorize.net/downloads/',
'version arguments' => array(
'file' => 'README',
'pattern' => '/Version (\d+)/',
'lines' => 206,
'version' => '1.1.8'
),
'files' => array(
'php' => array('AuthorizeNet.php'),
),
);
return $libraries;
}
然后在你的模块中包含依赖项。
/**
* Assemble and send DPM payment request to Authorize.net.
*/
function mymodule_process_payment($reservation) {
// Include/require the dependency using libraries_load().
$library = libraries_load('anet_php_sdk');
// Use the external dependency...
}
访问libraries 项目页面以获取更多文档,包括需要特定版本以及处理检查和通知的示例。