如何在Drupal-7中使用hook\u swiper\u options\u alter($node,$plugin\u options){}

如何在Drupal-7中使用hook\u swiper\u options\u alter($node,$plugin\u options){},drupal-7,swiper,Drupal 7,Swiper,我已经搜索了几天,想知道如何更改Drupal-7中swiper(V7.x-1.4)模块的选项。文档非常清楚,解释了模块希望如何使用这个钩子。我正在寻找一个关于如何从swiper API实现以下选项的简单代码示例: autoplay prevButton nextButton autoplayDisableOnInteraction 我能找到的唯一文档参考来自模块中的README.txt: ... You can also add, change and remove, any of API o

我已经搜索了几天,想知道如何更改Drupal-7中swiper(V7.x-1.4)模块的选项。文档非常清楚,解释了模块希望如何使用这个钩子。我正在寻找一个关于如何从swiper 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);
}

您可能需要通读以下文档:

  • .info
    文件中删除此行:
    文件[]=myCustom.module
    。Drupal将自动读取
    .module
    文件

  • 当您在
    .info
    文件中定义了版本时,这可能需要您注意:,但实际上您也可以忽略它,这不是强制性的

  • 由于您使用的是来自该swiper模块的挂钩,因此我建议将其设置为自定义模块的
    .info
    文件中的依赖项:
    依赖项[]=swiper
    ,以防止未满足的依赖项错误

  • $plugin\u选项
    数组更改为php数组&不要返回任何内容:

    <?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,
        );
    
    }
    

    成功!谢谢你,拜科!该模块现在可以正常工作,autoplay正在工作。“上一个/下一个”按钮还不起作用,但至少我知道我的选项正在被swiper模块读取。现在我可以从API中找出我想要使用的选项。