Drupal 页面管理器:我可以在我的模块中提供变体吗?

发布于 2024-12-10 03:20:35 字数 307 浏览 0 评论 0原文

我有一个模块,它使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

行至春深 2024-12-17 03:20:35

我找到了我要找的东西。

要为在代码中使用页面管理器构建的页面提供变体,请在模块文件中调用 hook_ctools_plugin_api(),让页面管理器知道它应该侦听您的模块:

/**
 * Implement hook_ctools_plugin_api().
 *
 * Tells ctools, page manager and panels, that we have a template ready
 */
function mtvideo_ctools_plugin_api($module, $api) {
  // @todo -- this example should explain how to put it in a different file.
  if ($module == 'panels_mini' && $api == 'panels_default') {
    return array('version' => 1);
  }
  if ($module == 'page_manager' && $api == 'pages_default') {
    return array('version' => 1);
  }
}

现在在模块根文件夹中创建一个名为 MODULE_NAME.pages_default 的新文件。公司
在此文件中,您现在可以包含以下功能:

hook_default_page_manager_pages()
/**
 * If you want to put an entire page including its variants in code.
 * With the export module from ctools, you can export your whole page to code.
 * Paste that into this function.
 * (Be aware that the export gives you $page, but you need to return an array,
 * So let the function return array('page name' => $page);
 */

和/或

hook_default_page_manager_handlers()
/**
 * This will provide a variant of an existing page, e.g. a variant of the system
 * page node/%node
 * Again, use the export function in Page Manager to export the needed code,
 * and paste that into the body of this function.
 * The export gives you $handler, but again you want to return an array, so use:
 * return array('handler name' => $handler);
 *
 * Notice, that if you export a complete page, it will include your variants.
 * So this function is only to provide variants of e.g. system pages or pages
 * added by other modules.
 */

我希望这有助于有一天有需要的人: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:

/**
 * Implement hook_ctools_plugin_api().
 *
 * Tells ctools, page manager and panels, that we have a template ready
 */
function mtvideo_ctools_plugin_api($module, $api) {
  // @todo -- this example should explain how to put it in a different file.
  if ($module == 'panels_mini' && $api == 'panels_default') {
    return array('version' => 1);
  }
  if ($module == 'page_manager' && $api == 'pages_default') {
    return array('version' => 1);
  }
}

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:

hook_default_page_manager_pages()
/**
 * If you want to put an entire page including its variants in code.
 * With the export module from ctools, you can export your whole page to code.
 * Paste that into this function.
 * (Be aware that the export gives you $page, but you need to return an array,
 * So let the function return array('page name' => $page);
 */

and/or

hook_default_page_manager_handlers()
/**
 * This will provide a variant of an existing page, e.g. a variant of the system
 * page node/%node
 * Again, use the export function in Page Manager to export the needed code,
 * and paste that into the body of this function.
 * The export gives you $handler, but again you want to return an array, so use:
 * return array('handler name' => $handler);
 *
 * Notice, that if you export a complete page, it will include your variants.
 * So this function is only to provide variants of e.g. system pages or pages
 * added by other modules.
 */

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 :)

黯然 2024-12-17 03:20:35

如果我误解了,请道歉,但我认为有两种方法可以解决这个问题:

首先,您可以实现 hook_menu_alter() 覆盖路径的页面回调:

function mymodule_menu_alter(&$items) {
  $items['node/%node']['page callback'] = 'mymodule_node_page_callback';
}

function mymodule_node_page_callback($node) {
  // Build up the content and return
}

在这种情况下,您需要确保在 system 表中,您的模块在 weight 列中的值高于页面管理器模块(因此稍后将调用您的钩子并获得最终的值)可以这么说)。

其次,您可以实现 hook_node_view() 并完全覆盖内容:

function hook_node_view($node, $view_mode, $langcode) {
  if ($view_mode == 'full') {
    $node->content = array();
    $node->content['title'] = array('#markup' => '<h1>' . $node->title . '</h1>';

    // Build up the rest of the content
  }
}

在这种情况下,您需要将内容构建为渲染数组(请参阅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:

function mymodule_menu_alter(&$items) {
  $items['node/%node']['page callback'] = 'mymodule_node_page_callback';
}

function mymodule_node_page_callback($node) {
  // Build up the content and return
}

In this case you'd need to make sure that in the system table your module has a higher value in the weight 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:

function hook_node_view($node, $view_mode, $langcode) {
  if ($view_mode == 'full') {
    $node->content = array();
    $node->content['title'] = array('#markup' => '<h1>' . $node->title . '</h1>';

    // Build up the rest of the content
  }
}

In this case you'll need to build up the content as a render array (see the drupal_render() function).

Hope that helps

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文