1

我一直在寻找几天来弄清楚如何在 Drupal-7 中更改 swiper (v 7.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);
}

我知道我有多个问题。Drupal 拒绝按原样启用我的模块,我不知道为什么。我检查了 admin->reports->recent log messages 报告,发现没有任何相关的东西至少可以帮助我进行故障排除。

有什么想法可以解决这个问题吗?有没有人有我可以复制和修改以使这个钩子工作的代码的工作示例?

提前感谢您的任何帮助!

4

1 回答 1

2

您可能需要通读此文档:Writing module .info files (Drupal 7.x)

  • .info从您的文件中删除这一行: files[] = myCustom.module. Drupal 会自动读取.module文件。

  • 当您在文件中定义版本.info时,这可能需要您注意:发布命名约定,但实际上您也可以将其省略,这不是强制性的。

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

  • 将数组更改$plugin_options为 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,
        );
    
    }
    
  • 另外:尽量避免根据机器名称(模块目录名称)在模块名称中使用大写字母。如果您查看其他 Drupal 模块,/modules或者sites/all/modules它们都是小写的。(您可以在.info文件中保留名称,该名称也代表您现在在模块列表中的模块。)

于 2015-06-06T18:53:47.193 回答