无法使用drupal模块创建块(Can't create a block with drupal module)

编程入门 行业动态 更新时间:2024-10-26 01:22:22
无法使用drupal模块创建块(Can't create a block with drupal module)

我正在尝试创建一个drupal模块附带的块。 我不能让它显示在我的阻止列表中。 我尝试了很多不同的教程,甚至只是复制粘贴,它仍然没有出现。 在我的drupal设置中是否可以阻止我的模块阻止显示? 或者代码中有什么问题吗?

模块显示并激活。

这是我现在的代码:

helicopter_contest_form.info我正在尝试创建一个drupal模块附带的块。 我不能让它显示在我的阻止列表中。 我尝试了很多不同的教程,甚至只是复制粘贴,它仍然没有出现。 在我的drupal设置中是否可以阻止我的模块阻止显示? 或者代码中有什么问题吗?

模块显示并激活。

这是我现在的代码:

helicopter_contest_form.info

;$Id$ name = Helicopter contest form description = Block module with a contest form core = 7.x package = My modules files[] = helicopter_contest_form.module

helicopter_contest_form.module

/** * Implements hook_block_info(). */ function membercount_block_info() { $blocks = array (); $blocks['count_members'] = array ( 'info' => t('Count Members'), 'cache' => DRUPAL_NO_CACHE, ); return $blocks; } /** * Implements hook_block_view(). */ function membercount_block_view($name) { if ($name == 'count_members') { $count = db_query('SELECT COUNT(uid) - 1 FROM {users}')->fetchField(); $content = format_plural($count, 'This site has 1 user.', 'This site has @count users.'); $block = array ( 'subject' => t('Members'), 'content' => $content, ); return $block; } }

在旁注中,我如何一次缩进所有代码4个空格? 我必须手工完成每一行,它也会破坏我的缩进...

I'm trying to create a block that comes with a drupal module. I can't get it to show up in my block list. I tried a lof of different tutorials, even just copy paste and it still doesn't show up. Could it be anything in my drupal settings that stops my modules block from showing up? Or is there anything wrong in the code?

The module shows and is activated.

This is my code right now:

helicopter_contest_form.info I'm trying to create a block that comes with a drupal module. I can't get it to show up in my block list. I tried a lof of different tutorials, even just copy paste and it still doesn't show up. Could it be anything in my drupal settings that stops my modules block from showing up? Or is there anything wrong in the code?

The module shows and is activated.

This is my code right now:

helicopter_contest_form.info

;$Id$ name = Helicopter contest form description = Block module with a contest form core = 7.x package = My modules files[] = helicopter_contest_form.module

helicopter_contest_form.module

/** * Implements hook_block_info(). */ function membercount_block_info() { $blocks = array (); $blocks['count_members'] = array ( 'info' => t('Count Members'), 'cache' => DRUPAL_NO_CACHE, ); return $blocks; } /** * Implements hook_block_view(). */ function membercount_block_view($name) { if ($name == 'count_members') { $count = db_query('SELECT COUNT(uid) - 1 FROM {users}')->fetchField(); $content = format_plural($count, 'This site has 1 user.', 'This site has @count users.'); $block = array ( 'subject' => t('Members'), 'content' => $content, ); return $block; } }

On a sidenote, how do I indent all my code 4 spaces at once? I have to do it each row by hand, it also ruins my indenting...

最满意答案

在实现钩子时,你应该用你的模块的短名称替换钩子名称中的“钩子”,所以只需将你的函数名称从membercount_block_info为helicopter_contest_form_block_info (“hook_block_view”也是如此)。

此外,实际上没有必要在.info文件中提及files[] = helicopter_contest_form.module ,因为无论如何都需要.module。

While implementing a hook you should replace "hook" in the hook name with your module's short name, so just change the name of your function from membercount_block_info to helicopter_contest_form_block_info (the same for "hook_block_view").

Also, there is actually no need to mention files[] = helicopter_contest_form.module in .info file because .module is required anyway.

更多推荐

本文发布于:2023-08-02 16:40:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1378340.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:模块   drupal   create   module   block

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!