如何在 Drupal-7 中使用 hook_swiper_options_alter($node, $plugin_options) {}
How to use hook_swiper_options_alter($node, $plugin_options) {} in Drupal-7
我已经搜索了几天,想弄清楚如何在 Drupal-7 中更改 swiper (v 7.x-1.4) 模块的选项。文档清楚地解释了模块期望如何使用这个钩子。我正在寻找一个简单的代码示例,说明如何从滑动器 API:
中实现以下选项
autoplay
prevButton
nextButton
autoplayDisableOnInteraction
我能找到的唯一文档参考来自模块中的 README.txt:
...
You can also add, change and remove, any of API options of the Swipers,
just you need to implement a hook:
hook_swiper_options_alter($node, $plugin_options) {}
This way the module will handle pass these options to the script that
instantiates the swiper Plugin.
...
我对 Drupal 还很陌生,但我正在努力学习。我试图创建一个简单的自定义模块来实现这些选项。我将我的模块命名为 myCustom,创建了包含以下文件的 /drupal/sites/all/modules/myCustom 目录:
myCustom.info:
name = myCustom
description = customize swiper
package = me
version = 0.02
core = 7.x
files[] = myCustom.module
myCustom.module:
<?php
function myCustom_swiper_options_alter($node, $plugin_options)
{
$plugin_options += (
nextButton: '.swiper-button-next',
prevButton: '.swiper-button-prev',
paginationClickable: true,
autoplay: 2500,
autoplayDisableOnInteraction: true
);
return($node, $plugin_options);
}
我知道我有很多问题。 Drupal 拒绝按原样启用我的模块,我不明白为什么。我已经检查了管理->报告->最近的日志消息报告,但没有发现任何相关内容至少可以帮助我解决问题。
有什么办法可以解决这个问题吗?有没有人有我可以复制和修改以使这个钩子工作的代码的工作示例?
提前感谢您的帮助!
您可能需要阅读此文档:Writing module .info files (Drupal 7.x)。
从您的 .info
文件中删除这一行:files[] = myCustom.module
。 Drupal 将自动读取 .module
文件。
您在 .info
文件中定义了 版本 ,这可能需要您注意:Release naming conventions,但实际上您可以把它也去掉,它不是强制性的。
由于您使用的是来自该 swiper 模块的钩子,我建议将其设置为自定义模块的 .info
文件中的依赖项:dependencies[] = swiper
以防止未满足依赖错误。
将 $plugin_options
数组更改为 php 数组并且不要 return 任何内容:
<?php
function YOUR_MODULE_swiper_options_alter($node, &$plugin_options) {
$plugin_options += array(
'nextButton' => '.swiper-button-next',
'prevButton' => '.swiper-button-prev',
'paginationClickable' => true,
'autoplay' => 2500,
'autoplayDisableOnInteraction' => true,
);
}
另外: 尽量避免在模块名称中使用大写字母 机器名称(模块目录名称) .如果您查看 /modules
或 sites/all/modules
中的其他 Drupal 模块,它们都是小写的。 (您可以将名称留在 .info
文件中,它也代表您现在在 模块列表 中的模块。)
我已经搜索了几天,想弄清楚如何在 Drupal-7 中更改 swiper (v 7.x-1.4) 模块的选项。文档清楚地解释了模块期望如何使用这个钩子。我正在寻找一个简单的代码示例,说明如何从滑动器 API:
中实现以下选项autoplay
prevButton
nextButton
autoplayDisableOnInteraction
我能找到的唯一文档参考来自模块中的 README.txt:
...
You can also add, change and remove, any of API options of the Swipers,
just you need to implement a hook:
hook_swiper_options_alter($node, $plugin_options) {}
This way the module will handle pass these options to the script that
instantiates the swiper Plugin.
...
我对 Drupal 还很陌生,但我正在努力学习。我试图创建一个简单的自定义模块来实现这些选项。我将我的模块命名为 myCustom,创建了包含以下文件的 /drupal/sites/all/modules/myCustom 目录:
myCustom.info:
name = myCustom
description = customize swiper
package = me
version = 0.02
core = 7.x
files[] = myCustom.module
myCustom.module:
<?php
function myCustom_swiper_options_alter($node, $plugin_options)
{
$plugin_options += (
nextButton: '.swiper-button-next',
prevButton: '.swiper-button-prev',
paginationClickable: true,
autoplay: 2500,
autoplayDisableOnInteraction: true
);
return($node, $plugin_options);
}
我知道我有很多问题。 Drupal 拒绝按原样启用我的模块,我不明白为什么。我已经检查了管理->报告->最近的日志消息报告,但没有发现任何相关内容至少可以帮助我解决问题。
有什么办法可以解决这个问题吗?有没有人有我可以复制和修改以使这个钩子工作的代码的工作示例?
提前感谢您的帮助!
您可能需要阅读此文档:Writing module .info files (Drupal 7.x)。
从您的
.info
文件中删除这一行:files[] = myCustom.module
。 Drupal 将自动读取.module
文件。您在
.info
文件中定义了 版本 ,这可能需要您注意:Release naming conventions,但实际上您可以把它也去掉,它不是强制性的。由于您使用的是来自该 swiper 模块的钩子,我建议将其设置为自定义模块的
.info
文件中的依赖项:dependencies[] = swiper
以防止未满足依赖错误。将
$plugin_options
数组更改为 php 数组并且不要 return 任何内容:<?php function YOUR_MODULE_swiper_options_alter($node, &$plugin_options) { $plugin_options += array( 'nextButton' => '.swiper-button-next', 'prevButton' => '.swiper-button-prev', 'paginationClickable' => true, 'autoplay' => 2500, 'autoplayDisableOnInteraction' => true, ); }
另外: 尽量避免在模块名称中使用大写字母 机器名称(模块目录名称) .如果您查看
/modules
或sites/all/modules
中的其他 Drupal 模块,它们都是小写的。 (您可以将名称留在.info
文件中,它也代表您现在在 模块列表 中的模块。)