Drupal 页面管理器:我可以在我的模块中提供变体吗?
我有一个模块,它使用 hook_default_page_manager_pages()
向页面管理器模块提供多个页面。这效果很好。 但现在我还想为系统提供一个变体,包括node/%node page
。但我找不到任何提供变体的钩子。
我的问题是,我无法创建自己的页面来覆盖 node/%node,因为这已经由页面管理器模块本身提供,所以我可以创建接管正常节点视图的页面的唯一方法是提供变体(根据我的理解)。 但我怎样才能以编程方式做到这一点呢? 我可以看到可以导出变体,因此我猜想也可以通过钩子提供它?
这有可能吗?
I have a module that provides a number of pages to the Page Manager module using hook_default_page_manager_pages()
. This works out fine.
But now I would also like to provide a variant for the system included node/%node page
. But I can't find any hooks for providing variants.
My problem is, that I can not create my own page to overwrite node/%node, since this is already provided by the Page Manager module itself, so only way I can create pages that takes over the normal node view, is to provide a variant (from my understanding).
But how can I do this programmatically?
I can see that it's possible to export the variant, and therefore I guess that it would also be possible to provide it through a hook?
Is this possible in any way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我找到了我要找的东西。
要为在代码中使用页面管理器构建的页面提供变体,请在模块文件中调用 hook_ctools_plugin_api(),让页面管理器知道它应该侦听您的模块:
现在在模块根文件夹中创建一个名为 MODULE_NAME.pages_default 的新文件。公司
在此文件中,您现在可以包含以下功能:
和/或
我希望这有助于有一天有需要的人:o)
我唯一需要发现的是我的模块如何以编程方式启用页面管理器中的 node/%node 页面。
如果有人有线索,请随时与我分享:)
I found what I was looking for.
To provide variants for pages build with page manager in code, in your module file call hook_ctools_plugin_api(), to let Page Manager know, that it should listen to your module:
Now create a new file in your module root folder called MODULE_NAME.pages_default.inc.
In this file you can now include the following functions:
and/or
I hope this helps another in need one day :o)
Only thing I have left to discover is how my module programmatically can enable the node/%node page in Page Manager.
If any one has a clue feel free to share it with me :)
如果我误解了,请道歉,但我认为有两种方法可以解决这个问题:
首先,您可以实现
hook_menu_alter()
覆盖路径的页面回调:在这种情况下,您需要确保在
system
表中,您的模块在weight
列中的值高于页面管理器模块(因此稍后将调用您的钩子并获得最终的值)可以这么说)。其次,您可以实现
hook_node_view()
并完全覆盖内容:在这种情况下,您需要将内容构建为渲染数组(请参阅
drupal_render()
函数)。希望有帮助
Apologies if I've misunderstood but I think there are two ways you could attack this:
Firstly you could implement
hook_menu_alter()
to override the page callback for the path:In this case you'd need to make sure that in the
system
table your module has a higher value in theweight
column than the Page Manager module (so your hook will be called later on and will have the final say as it were).Secondly you could implement
hook_node_view()
and just override the content altogether:In this case you'll need to build up the content as a render array (see the
drupal_render()
function).Hope that helps